我得到的错误Insufficient number of arguments or no entry found. Alternatively, run 'webpack(-cli) --help' for usage info.
,当我运行命令npm run dev
我也收到这下一个一个错误,指出ERROR in Entry module not found: Error: Can't resolve
后跟路径。我不太确定为什么它找不到入口点,将不胜感激。
将整个项目上传到github以帮助提高可视性。https://github.com/dustinm94/coding-challenge
webpack.config.js
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
}
]
}
}
package.json
{
"name": "coding_challenge",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "webpack --mode development --watch ./coding/frontend/src/index.js --output ./coding/frontend/static/frontend/main.js",
"build": "webpack --mode production ./coding/frontend/src/index.js --output ./coding/frontend/static/frontend/main.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@babel/core": "^7.4.0",
"@babel/preset-env": "^7.4.2",
"@babel/preset-react": "^7.0.0",
"babel-loader": "^8.0.5",
"babel-plugin-transform-class-properties": "^6.24.1",
"webpack": "^4.29.6",
"webpack-cli": "^3.3.0"
},
"dependencies": {
"babel-preset-react": "^6.24.1",
"prop-types": "^15.7.2",
"react": "^16.8.6",
"react-dom": "^16.8.6"
}
}
.babelrc
{
"presets": ["@babel/preset-env", "@babel/preset-react"],
"plugins": ["transform-class-properties"]
}
webpack.config.js
并且package.json
总是会在你的项目基本路径和节点的命令应该从这个路径被触发
您必须在webpack.config.js
&中进行以下更正package.json
--watch
会自动在entry
object in中查找指定的文件,webpack.config.js
并继续观察其依赖关系图以在检测到更改时自动重新加载。您需要package.json
使用以下详细信息进行更新
"scripts": {
"webpack" : "webpack", // invoke this command from npm run dev & npm run build
"dev": "npm run webpack -- --mode development --watch",
"build": "npm run webpack -- --mode production"
}
在监视模式下运行可能会导致性能问题,具体取决于您所使用的硬件,请阅读有关它的更多信息。
将entry
对象添加到中webpack.config.js
。如果您没有覆盖输入对象,则默认情况下,webpack会将entry
对象指向' 。/ src / index.js`。由于您未在项目中使用默认配置,因此webpack会引发错误
ERROR in Entry module not found: Error: Can't resolve './src' in '/root/../coding_challenge'
要解决该错误,您需要entry
使用目标js
文件覆盖该对象,如下所示
module.exports = {
entry : "./frontend/src/index.js",
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
}
]
}
}
如果进行了上述更正,
npm run dev
将以监视模式运行您的项目
npm run build
将为您的项目生成生产版本
让我知道此信息是否解决了您的问题
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句