我正尝试跟随这个教程。
当我运行npm start
时,会出现以下错误:
PS C:\Users\user\Desktop\Projects\Websites\project\project> npm start
> PROJECT@0.0.0 start C:\Users\user\Desktop\Projects\Websites\project\project
> webpack-dev-server --config webpack.config.js --open
'find_dp0' is not recognized as an internal or external command,
operable program or batch file.
internal/modules/cjs/loader.js:775
throw err;
^
Error: Cannot find module 'C:\webpack-dev-server\bin\webpack-dev-server.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:772:15)
at Function.Module._load (internal/modules/cjs/loader.js:677:27)
at Function.Module.runMain (internal/modules/cjs/loader.js:999:10)
at internal/main/run_main_module.js:17:11 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
我认为主要问题在于它正在寻找位于我的
C:/
磁盘上的 webpack-dev-server
模块,因为错误信息显示为:Error: Cannot find module 'C:\webpack-dev-server\bin\webpack-dev-server.js'
为什么它会在本地的
node_modules
文件夹之外查找模块呢?这至少是我认为导致问题的原因,也许还有其他的原因?我在网上找不到类似的错误信息(它在用户的
C:/
驱动器中查找)。我正在使用Visual Studio Community 2019。非常感谢任何帮助!
package.json
:
{
"name": "drewpel.com",
"description": "drewpel.com",
"author": "James Pelusi",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "webpack-dev-server --config webpack.config.js --open",
"test": "echo \"Error: no test script was specified\" && exit 1"
},
"dependencies": {
"express": "4.17.1",
"morgan": "1.10.0",
"pug": "3.0.0"
},
"devDependencies": {
"css-loader": "4.2.2",
"extract-loader": "5.1.0",
"file-loader": "6.0.0",
"sass": "1.26.10",
"sass-loader": "10.0.1",
"webpack": "4.44.1",
"webpack-cli": "3.3.12",
"webpack-dev-server": "3.11.0"
}
}
webpack.config.js
:
module.exports = [{
entry: './css/index.scss',
output: {
// This is necessary for webpack to compile
// But we never use style-bundle.js
filename: 'style-bundle.js',
},
module: {
rules: [
{
test: /\.scss$/,
use: [
{
loader: 'file-loader',
options: {
name: 'bundle.css',
},
},
{ loader: 'extract-loader' },
{ loader: 'css-loader' },
{
loader: 'sass-loader',
options: {
// Prefer Dart Sass
implementation: require('sass'),
// See https://github.com/webpack-contrib/sass-loader/issues/804
webpackImporter: false,
},
},
]
}
]
},
}];