对于在我的package.json
文件中为本地安装的模块设置的任何脚本,npm表示找不到该命令。
下面是我的package.json。我已经运行了“ npm install”,安装软件包没有任何问题。
{
"name": "app",
"private": true,
"dependencies": {
"@babel/core": "^7.8.6",
"@babel/preset-env": "^7.8.6",
"@babel/preset-react": "^7.8.3",
"babel-loader": "^8.0.6",
"bootstrap": "^4.4.1",
"jquery": "^1.9.1",
"react": "^16.13.0",
"react-dom": "^16.13.0",
"react-owl-carousel": "^2.3.1",
"react-redux": "^7.2.0",
"react-router-dom": "^5.1.2",
"react-slick": "^0.25.2",
"reactstrap": "^8.4.1",
"redux": "^4.0.5",
"redux-logger": "^3.0.6",
"redux-thunk": "^2.3.0",
"slick-carousel": "^1.8.1",
"webpack-cli": "^3.3.11"
},
"scripts": {
"postinstall": "webpack",
"start": "webpack --watch --mode=development"
},
"engines": {
"node": "10.13.0",
"npm": "6.4.1"
},
"devDependencies": {
"css-loader": "^3.4.2",
"style-loader": "^1.1.3",
"webpack": "^4.42.0"
}
}
当我尝试从根文件运行npm start
时,出现以下错误:
sh: webpack: command not found
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! app@ start: `webpack --watch --mode=development`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the app@ start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
我在多个项目中都有同样的问题。如果我在全球范围内安装,它将可以正常工作,但是据我对webpack的了解,这不是必须的,因此不建议使用:https://webpack.js.org/guides/installation/#global-installation。
有什么想法可能会带来麻烦吗?谢谢!
答案 0 :(得分:0)
问题是我的应用所在的目录的目录名称中有一个/
(例如a/b > app > node_modules
)。 /
被解释为:
,npm不喜欢。