【发布时间】:2019-01-14 22:53:36
【问题描述】:
我刚开始从这个网站tutorailspoint and React.js学习react.js。
在我运行此命令npm start 时遵循所有设置信息后,会出现以下错误:
C:\Users\USER\Desktop\reactapp>npm start
> reactapp@0.0.1 start C:\Users\USER\Desktop\reactapp
> webpack-dev-server.cmd --content-base app
The CLI moved into a separate package: webpack-cli.
Please install 'webpack-cli' in addition to webpack itself to use the CLI.
-> When using npm: npm install webpack-cli -D
-> When using yarn: yarn add webpack-cli -D
module.js:442
throw err;
^
Error: Cannot find module 'webpack-cli/bin/config-yargs'
at Function.Module._resolveFilename (module.js:440:15)
at Function.Module._load (module.js:388:25)
at Module.require (module.js:468:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (C:\Users\USER\Desktop\reactapp\node_modules\webpack-dev-server\bin\webpack-dev-server.js:65:1)
安装后
C:\Users\USER\Desktop\reactapp>npm start
> reactapp@0.0.1 start C:\Users\USER\Desktop\reactapp
> webpack-dev-server --hot
× 「wds」: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
- configuration.module has an unknown property 'loaders'. These properties are valid:
object { exprContextCritical?, exprContextRecursive?, exprContextRegExp?, exprContextRequest?, noParse?, rules?, defaultRules?, unknownContextCritical?, unknownContextRecursive?, unknownContextRegExp?, unknownContextRequest?, unsafeCache?, wrappedContextCritical?, wrappedContextRecursive?, wrappedContextRegExp?, strictExportPresence?, strictThisContextOnImports? }
-> Options affecting the normal modules (`NormalModuleFactory`).
npm ERR! Windows_NT 10.0.17134
我的 package.json 安装后:
{
"name": "reactapp",
"version": "0.0.1",
"description": "first test",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server --hot"
},
"author": "",
"license": "ISC",
"dependencies": {
"react": "^16.4.2",
"react-dom": "^16.4.2",
"webpack": "^4.16.5",
"webpack-dev-server": "^3.1.5"
},
"devDependencies": {
"webpack-cli": "^3.1.0"
}
}
【问题讨论】:
-
你运行 npm i 了吗?
-
该错误告诉您“CLI 已移入单独的包:webpack-cli。”。如果您正在学习旧教程,则可能不会提及。试试
npm i -D webpack-cli然后npm start -
不知道今天我才刚开始,你能建议如何运行npm i
-
如果你可以运行
npm start,你已经安装了npm,也可以写npm inpm install -
CodeSandbox 是在浏览器中开始的好方法。如果你不想在刚开始的时候自己配置 Webpack,你可以使用Create React App,这也很棒。
标签: node.js reactjs webpack webpack-dev-server webpack-4