当前正在通过一些教程学习Vue js和Express js,但我仍然是这些技术的新手。
无论如何,在教程之后,我都会构建一个小项目,其中有一个包含项目前端的文件夹“ Client”和另一个包含后端的服务器“ Server”。
就在将提交推送到Github之前,一切都很好,但是一旦我做了Github,便发出了一些漏洞,并在修复了npm后运行dev不再起作用。
尝试了多重解决方案,但无济于事,运行 npm cache clean --force
后,重新安装了可疑模块,重新安装了节点模块。这是我得到的错误
npm run dev
> client@1.0.0 dev D:\projects\Fullstack web apps\VueJs ExpressJs\tab-tracker\Client
> webpack-dev-server --inline --progress --config build/webpack.dev.conf.js
D:\projects\Fullstack web apps\VueJs ExpressJs\tab-tracker\Client\node_modules\copy-webpack-plugin\node_modules\schema-utils\dist\validate.js:88
throw new _ValidationError.default(errors, schema, configuration);
^
ValidationError: Invalid options object. Copy Plugin has been initialized using an options object that does not match the API schema.
- options[0] misses the property 'patterns'. Should be:
[non-empty string | object { from, to?, context?, globOptions?, toType?, force?, flatten?, transform?, cacheTransform?, transformPath?, noErrorOnMissing? }, ...] (should not have fewer than 1 item)
at validate (D:\projects\Fullstack web apps\VueJs ExpressJs\tab-tracker\Client\node_modules\copy-webpack-plugin\node_modules\schema-utils\dist\validate.js:88:11)
at new CopyPlugin (D:\projects\Fullstack web apps\VueJs ExpressJs\tab-tracker\Client\node_modules\copy-webpack-plugin\dist\index.js:24:30)
at Object.<anonymous> (D:\projects\Fullstack web apps\VueJs ExpressJs\tab-tracker\Client\build\webpack.dev.conf.js:61:5)
at Module._compile (internal/modules/cjs/loader.js:1133:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
at Module.load (internal/modules/cjs/loader.js:977:32)
at Function.Module._load (internal/modules/cjs/loader.js:877:14)
at Module.require (internal/modules/cjs/loader.js:1019:19)
at require (internal/modules/cjs/helpers.js:77:18)
at WEBPACK_OPTIONS (D:\projects\Fullstack web apps\VueJs ExpressJs\tab-tracker\Client\node_modules\webpack-cli\bin\utils\convert-argv.js:114:13)
at requireConfig (D:\projects\Fullstack web apps\VueJs ExpressJs\tab-tracker\Client\node_modules\webpack-cli\bin\utils\convert-argv.js:116:6)
at D:\projects\Fullstack web apps\VueJs ExpressJs\tab-tracker\Client\node_modules\webpack-cli\bin\utils\convert-argv.js:123:17
at Array.forEach (<anonymous>)
at module.exports (D:\projects\Fullstack web apps\VueJs ExpressJs\tab-tracker\Client\node_modules\webpack-cli\bin\utils\convert-argv.js:121:15)
at Object.<anonymous> (D:\projects\Fullstack web apps\VueJs ExpressJs\tab-tracker\Client\node_modules\webpack-dev-server\bin\webpack-dev-server.js:84:40)
at Module._compile (internal/modules/cjs/loader.js:1133:30) {
errors: [
{
keyword: 'required',
dataPath: '[0]',
schemaPath: '#/required',
params: [Object],
message: "should have required property 'patterns'",
schema: [Object],
parentSchema: [Object],
data: [Object],
children: [Array]
}
],
schema: {
definitions: { ObjectPattern: [Object], StringPattern: [Object] },
type: 'object',
additionalProperties: false,
properties: { patterns: [Object], options: [Object] },
required: [ 'patterns' ]
},
headerName: 'Copy Plugin',
baseDataPath: 'options',
postFormatter: null
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! client@1.0.0 dev: `webpack-dev-server --inline --progress --config build/webpack.dev.conf.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the client@1.0.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\iheb\AppData\Roaming\npm-cache\_logs\2020-05-21T13_56_52_099Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! client@1.0.0 start: `npm run dev`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the client@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\iheb\AppData\Roaming\npm-cache\_logs\2020-05-21T13_56_52_148Z-debug.log
这是日志文件:
0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'run',
1 verbose cli 'build:server'
1 verbose cli ]
2 info using npm@6.14.4
3 info using node@v12.16.3
4 verbose stack Error: missing script: build:server
4 verbose stack at run (C:\Program Files\nodejs\node_modules\npm\lib\run-script.js:155:19)
4 verbose stack at C:\Program Files\nodejs\node_modules\npm\lib\run-script.js:63:5
4 verbose stack at C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:116:5
4 verbose stack at C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:436:5
4 verbose stack at checkBinReferences_ (C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:391:45)
4 verbose stack at final (C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:434:3)
4 verbose stack at then (C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:161:5)
4 verbose stack at C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:281:12
4 verbose stack at C:\Program Files\nodejs\node_modules\npm\node_modules\graceful-fs\graceful-fs.js:115:16
4 verbose stack at FSReqCallback.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:63:3)
5 verbose cwd D:\projects\Fullstack web apps\VueJs ExpressJs\tab-tracker\Client
6 verbose Windows_NT 10.0.18362
7 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "build:server"
8 verbose node v12.16.3
9 verbose npm v6.14.4
10 error missing script: build:server
11 verbose exit [ 1, true ]
运行 npm审核会显示以下内容:
Moderate Cross-Site Scripting Package serialize-javascript Patched in >=2.1.1 Dependency of uglifyjs-webpack-plugin [dev] Path uglifyjs-webpack-plugin > serialize-javascript More info https://npmjs.com/advisories/1426
相关依赖项
“ webpack”:“ ^ 4.43.0”,
"webpack-bundle-analyzer": "^3.3.2", "webpack-cli": "^3.3.11", "webpack-dev-server": "^3.1.11",
我希望我为你们提供了一切,如果没有,我会立即提供一切帮助澄清我的问题,因为我说我是Web开发的新手。
更新:我正在尝试找出此类错误的原因,该问题在更新 webpack-dev-server 后出现 可以使用的版本:
“ webpack-dev-server”:“ ^ 2.9.1”
有错误的版本:
“ webpack-dev-server”:“ ^ 3.11.0”
如果我忽略发现的漏洞,可以吗?因为尝试修复它们会导致此错误。
谢谢
答案 0 :(得分:59)
这不是webpack
或webpack-dev-server
本身的问题,而是copy-webpack-plugin
插件的问题。
对6.x主版本的更新带来了重大变化:您不仅必须将带有配置模式的数组直接传递给CopyWebpackPlugin
构造函数,还必须将其包装在{{1}中}对象的属性并将其传递。
旧语法:
patterns
新语法:
new CopyWebpackPlugin(
[
{ from: 'src/xxx.ext', to: 'dist/xxx.ext' },
{ from: 'src/yyy.ext', to: 'dist/yyy.ext' }
]
)
之所以这样做,是因为构造函数现在支持附加的 new CopyWebpackPlugin(
{
patterns: [
{ from: 'src/xxx.ext', to: 'dist/xxx.ext' },
{ from: 'src/yyy.ext', to: 'dist/yyy.ext' }
]
}
)
属性:
https://webpack.js.org/plugins/copy-webpack-plugin/#options-1
答案 1 :(得分:38)
更新到3.11后,出现了一个新模板
plugins: [
new CopyPlugin({
patterns: [
{ from: 'source', to: 'dest' },
{ from: 'other', to: 'public' },
],
}),
],
答案 2 :(得分:7)
我有同样的问题。最后,我能够使用
解决它npm install --save copy-webpack-plugin@5.1.1
答案 3 :(得分:4)
如果您升级到copy-webpack-plugin:package.json中的^ 6.0.3,则在以前复制整个目录时,以下内容应该可以工作:
plugins: [
new CopyWebpackPlugin({
patterns: [
{
from: "[your-src-dir]/*",
to: "[your-dst-dir]/*",
},
],
}),
]
在目录目标和源目录名称之后添加/ *来修复它,而不会忽略漏洞,这是您永远都不会做的。
答案 4 :(得分:2)
这对我有用
在webpack.config.js文件中的更改 CopyWebpackPlugin
new CopyWebpackPlugin({
patterns: [
{ from: "fonts/**", globOptions: { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] } },
{ from: "**/*.{jpg,png}", globOptions: { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] } },
]
}),
希望我能帮忙
答案 5 :(得分:0)
使用以下命令将角度工具箱版本重置为2.3.0。
03 02