gpt4 book ai didi

node.js - 无法启动 webpack-dev-server - 找不到模块

转载 作者:行者123 更新时间:2023-12-04 01:14:59 25 4
gpt4 key购买 nike

(我正在尝试关注 this tutorial )

当我运行 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,
},
},
]
}
]
},
}];

最佳答案

"start": "webpack serve --config webpack.config.js --open" 

将 package.json 的开头更改为上面的这个。我希望它会起作用

关于node.js - 无法启动 webpack-dev-server - 找不到模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63638336/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com