我正在开始做出反应,因此尝试以不同的例子为基础。我的应用程序运行正常,但随后尝试启动服务器[npm start]并收到以下错误。我不确定我已更改了什么,尽管显然我已损坏了某些内容。关于什么原因的任何指导?
src / index.js
import * as React from 'react'
import * as ReactDOM from 'react-dom'
import { createHashHistory } from 'history'
import Main from 'main'
import * as serviceWorker from 'serviceWorker'
import configureStore from 'configureStore'
import 'typeface-ibm-plex-sans'
import 'styles'
const history = createHashHistory()
const initialState = window.initialReduxState
const store = configureStore(history, initialState)
ReactDOM.render(<Main store={store} history={history} />, document.getElementById('root'))
serviceWorker.unregister()
src / configureStore.ts
import { Store, createStore, applyMiddleware } from 'redux'
import createSagaMiddleware from 'redux-saga'
import { connectRouter, routerMiddleware } from 'connected-react-router'
import { composeWithDevTools } from 'redux-devtools-extension'
import { History } from 'history'
import { ApplicationState, rootReducer, rootSaga } from 'store'
export default function configureStore(
history: History,
initialState: ApplicationState
): Store<ApplicationState> {
// create the composing function for our middlewares
const composeEnhancers = composeWithDevTools({})
// create the redux-saga middleware
const sagaMiddleware = createSagaMiddleware()
const store = createStore(
connectRouter(history)(rootReducer),
initialState,
composeEnhancers(applyMiddleware(routerMiddleware(history), sagaMiddleware))
)
sagaMiddleware.run(rootSaga)
return store
}
tsconfig.json
{
"compilerOptions": {
"baseUrl": "./src",
"outDir": "build/dist",
"module": "esnext",
"target": "ES2017",
"lib":["es2015", "es2016","dom"],
"sourceMap": true,
"allowJs": true,
"jsx": "react",
"moduleResolution": "node",
"rootDir": "src",
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": true,
}
}
调试日志
0 info it worked if it ends with ok
1 verbose cli [ '/home/n4nite/.nvm/versions/node/v8.11.3/bin/node',
1 verbose cli '/home/n4nite/.nvm/versions/node/v8.11.3/bin/npm',
1 verbose cli 'install',
1 verbose cli 'configureStore',
1 verbose cli '--save' ]
2 info using npm@5.6.0
3 info using node@v8.11.3
4 verbose npm-session 0accc0570fa2177a
5 silly install loadCurrentTree
6 silly install readLocalPackageData
7 http fetch GET 404 https://registry.npmjs.org/configureStore 1116ms
8 silly fetchPackageMetaData error for configureStore@latest 404 Not Found: configureStore@latest
9 verbose stack Error: 404 Not Found: configureStore@latest
9 verbose stack at fetch.then.res (/home/n4nite/.nvm/versions/node/v8.11.3/lib/node_modules/npm/node_modules/pacote/lib/fetchers/registry/fetch.js:42:19)
9 verbose stack at runCallback (timers.js:810:20)
9 verbose stack at tryOnImmediate (timers.js:768:5)
9 verbose stack at processImmediate [as _immediateCallback] (timers.js:745:5)
9 verbose stack From previous event:
9 verbose stack at regFetch (/home/n4nite/.nvm/versions/node/v8.11.3/lib/node_modules/npm/node_modules/pacote/lib/fetchers/registry/fetch.js:36:6)
9 verbose stack at fetchPackument (/home/n4nite/.nvm/versions/node/v8.11.3/lib/node_modules/npm/node_modules/pacote/lib/fetchers/registry/manifest.js:81:10)
9 verbose stack at getManifest (/home/n4nite/.nvm/versions/node/v8.11.3/lib/node_modules/npm/node_modules/pacote/lib/fetchers/registry/manifest.js:37:10)
9 verbose stack at manifest (/home/n4nite/.nvm/versions/node/v8.11.3/lib/node_modules/npm/node_modules/pacote/lib/fetchers/registry/manifest.js:24:10)
9 verbose stack at Object.manifest (/home/n4nite/.nvm/versions/node/v8.11.3/lib/node_modules/npm/node_modules/pacote/lib/fetchers/registry/index.js:12:12)
9 verbose stack at Object.Fetcher#manifest [as manifest] (/home/n4nite/.nvm/versions/node/v8.11.3/lib/node_modules/npm/node_modules/pacote/node_modules/protoduck/node_modules/genfun/lib/genfun.js:15:38)
9 verbose stack at manifest (/home/n4nite/.nvm/versions/node/v8.11.3/lib/node_modules/npm/node_modules/pacote/lib/fetch.js:16:18)
9 verbose stack at pinflight (/home/n4nite/.nvm/versions/node/v8.11.3/lib/node_modules/npm/node_modules/pacote/manifest.js:24:12)
9 verbose stack at /home/n4nite/.nvm/versions/node/v8.11.3/lib/node_modules/npm/node_modules/promise-inflight/inflight.js:29:24
9 verbose stack From previous event:
9 verbose stack at _inflight (/home/n4nite/.nvm/versions/node/v8.11.3/lib/node_modules/npm/node_modules/promise-inflight/inflight.js:28:25)
9 verbose stack at /home/n4nite/.nvm/versions/node/v8.11.3/lib/node_modules/npm/node_modules/promise-inflight/inflight.js:22:14
9 verbose stack at runCallback (timers.js:810:20)
9 verbose stack at tryOnImmediate (timers.js:768:5)
9 verbose stack at processImmediate [as _immediateCallback] (timers.js:745:5)
9 verbose stack From previous event:
9 verbose stack at inflight (/home/n4nite/.nvm/versions/node/v8.11.3/lib/node_modules/npm/node_modules/promise-inflight/inflight.js:14:40)
9 verbose stack at Object.manifest (/home/n4nite/.nvm/versions/node/v8.11.3/lib/node_modules/npm/node_modules/pacote/manifest.js:22:10)
9 verbose stack at fetchPackageMetadata (/home/n4nite/.nvm/versions/node/v8.11.3/lib/node_modules/npm/lib/fetch-package-metadata.js:58:10)
9 verbose stack at limited (/home/n4nite/.nvm/versions/node/v8.11.3/lib/node_modules/npm/node_modules/call-limit/call-limit.js:29:10)
9 verbose stack at fs.stat (/home/n4nite/.nvm/versions/node/v8.11.3/lib/node_modules/npm/lib/install/deps.js:219:20)9 verbose stack at /home/n4nite/.nvm/versions/node/v8.11.3/lib/node_modules/npm/node_modules/graceful-fs/polyfills.js:284:29
9 verbose stack at FSReqWrap.oncomplete (fs.js:152:21)
10 verbose cwd /mnt/c/Users/micha/github/infornite-web-ui
11 verbose Linux 4.4.0-17134-Microsoft
12 verbose argv "/home/n4nite/.nvm/versions/node/v8.11.3/bin/node" "/home/n4nite/.nvm/versions/node/v8.11.3/bin/npm" "install" "configureStore" "--save"
13 verbose node v8.11.3
14 verbose npm v5.6.0
15 error code E404
16 error 404 Not Found: configureStore@latest
17 verbose exit [ 1, true ]
package.json
{
"name": "infornite-web-ui",
"version": "0.1.0",
"private": true,
"dependencies": {
"@types/classnames": "^2.2.6",
"@types/material-ui": "^0.21.5",
"@types/prop-types": "^15.5.5",
"@types/react-router": "^4.0.30",
"@types/redux-form": "^7.4.5",
"babel-plugin-emotion": "^9.2.0",
"class-names": "^1.0.0",
"classnames": "^2.2.6",
"connected-react-router": "^4.3.0",
"create-react-app-parcel-typescript": "0.0.5",
"dotenv-expand": "^4.2.0",
"emotion": "^9.2.3",
"emotion-theming": "^9.2.3",
"history": "^4.7.2",
"http2": "^3.3.7",
"main": "^1.0.1",
"material-ui": "^0.20.2",
"moment": "^2.22.2",
"polished": "^1.9.3",
"react": "^16.4.1",
"react-dom": "^16.4.1",
"react-emotion": "^9.2.3",
"react-redux": "^5.0.7",
"react-router-dom": "^4.3.1",
"react-router-redux": "^5.0.0-alpha.9",
"redux": "^4.0.0",
"redux-devtools-extension": "^2.13.2",
"redux-form": "^7.4.2",
"redux-form-material-ui": "^4.3.4",
"redux-saga": "^0.16.0",
"routes": "^2.1.0",
"store": "^2.0.12",
"styles": "^0.2.1",
"typeface-ibm-plex-mono": "^0.0.56",
"typeface-ibm-plex-sans": "^0.0.58",
"typesafe-actions": "^2.0.4",
"utils": "^0.3.1"
},
"scripts": {
"start": "react-scripts-parcel start",
"build": "react-scripts-parcel build",
"test": "react-scripts-parcel test --env=jsdom",
"eject": "react-scripts-parcel eject"
},
"browserslist": {
"development": [
"last 2 chrome versions",
"last 2 firefox versions",
"last 2 edge versions"
],
"production": [
">1%",
"Firefox ESR",
"not ie <= 11",
"not op_mini all"
]
},
"devDependencies": {
"@types/history": "^4.6.2",
"@types/node": "^10.3.3",
"@types/react": "^16.3.17",
"@types/react-dom": "^16.0.6",
"@types/react-redux": "^6.0.2",
"@types/react-router-dom": "^4.2.7",
"@types/react-router-redux": "^5.0.15",
"tslint": "^5.10.0",
"tslint-config-blvd": "^1.0.0",
"typescript": "^2.9.2"
}
}
答案 0 :(得分:0)
实际上,configureStore
在NPM上不可用:https://www.npmjs.com/package/configureStore给出“未找到”错误(例如,与反应https://www.npmjs.com/package/react比较)
要么package.json错误(不太可能),要么您应该在组织本地注册。在npm中使用--registry
标志,并询问队友。
答案 1 :(得分:0)
以防其他任何人遇到此问题。我在tsconfig.json文件中使用一个选项将基本URL设置为“ ./src”。目的是我可以在导入语句中使用相对于src目录的路径,而不是完整路径,例如
[从'../../../my-module'导入一些东西
将成为
[从“我的模块”中导入一些东西]
这很好,但是突然我开始收到错误消息。我以为我要么安装了一些不支持相对路径的配置的依赖项(不太可能),要么我无意中做了一些改动,破坏了这个逻辑,却没有意识到自己做了(很可能)。
解决方法是将基本URL从“ baseUrl”:“ ./ src”更改为“ baseUrl”:“。”如@rshepp所建议。完成此操作后,我必须返回并更改每个使用相对路径的导入语句以使用完整路径。那很痛苦,但解决了问题。