webpack错误:自定义关键字定义无效:数据/错误应为布尔值

时间:2019-02-10 08:37:00

标签: node.js npm webpack

我正在使用webpack捆绑两个js文件(test.js和index.js) 这就是test.js的样子

console.log("i'm in test.js");
export default 35;

这就是index.js的样子

const num = require("./test");
console.log("Successfully export the number: " + num);

这是我的package.json文件的样子

 "scripts": {
    "dev": "webpack"
  },

 "devDependencies": {
    "webpack": "^4.29.3",
    "webpack-cli": "^3.2.3"
  }

当我运行命令“ npm run dev”时,我的两个文件都正常工作。

> forkify@1.0.0 dev C:\Users\Seinfeld\Desktop\js\complete-javascript-course-master\9-forkify\starter
> webpack

C:\Users\Seinfeld\Desktop\js\complete-javascript-course-master\9-forkify\starter\node_modules\webpack-cli\bin\cli.js:231
                                throw err;
                                ^

Error: custom keyword definition is invalid: data/errors should be boolean
    at Ajv.addKeyword (C:\Users\Seinfeld\Desktop\js\complete-javascript-course-master\9-forkify\starter\node_modules\ajv\lib\keyword.js:65:13)
    at module.exports (C:\Users\Seinfeld\Desktop\js\complete-javascript-course-master\9-forkify\starter\node_modules\ajv-errors\index.js:10:7)
    at Object.<anonymous> (C:\Users\Seinfeld\Desktop\js\complete-javascript-course-master\9-forkify\starter\node_modules\schema-utils\src\validateOptions.js:22:1)
    at Module._compile (C:\Users\Seinfeld\Desktop\js\complete-javascript-course-master\9-forkify\starter\node_modules\v8-compile-cache\v8-compile-cache.js:178:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (C:\Users\Seinfeld\Desktop\js\complete-javascript-course-master\9-forkify\starter\node_modules\v8-compile-cache\v8-compile-cache.js:159:20)
    at Object.<anonymous> (C:\Users\Seinfeld\Desktop\js\complete-javascript-course-master\9-forkify\starter\node_modules\schema-utils\src\index.js:7:25)
    at Module._compile (C:\Users\Seinfeld\Desktop\js\complete-javascript-course-master\9-forkify\starter\node_modules\v8-compile-cache\v8-compile-cache.js:178:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (C:\Users\Seinfeld\Desktop\js\complete-javascript-course-master\9-forkify\starter\node_modules\v8-compile-cache\v8-compile-cache.js:159:20)
    at Object.<anonymous> (C:\Users\Seinfeld\Desktop\js\complete-javascript-course-master\9-forkify\starter\node_modules\webpack\lib\SourceMapDevToolPlugin.js:13:25)
    at Module._compile (C:\Users\Seinfeld\Desktop\js\complete-javascript-course-master\9-forkify\starter\node_modules\v8-compile-cache\v8-compile-cache.js:178:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (C:\Users\Seinfeld\Desktop\js\complete-javascript-course-master\9-forkify\starter\node_modules\v8-compile-cache\v8-compile-cache.js:159:20)
    at Object.<anonymous> (C:\Users\Seinfeld\Desktop\js\complete-javascript-course-master\9-forkify\starter\node_modules\webpack\lib\WebpackOptionsApply.js:16:32)
    at Module._compile (C:\Users\Seinfeld\Desktop\js\complete-javascript-course-master\9-forkify\starter\node_modules\v8-compile-cache\v8-compile-cache.js:178:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! forkify@1.0.0 dev: `webpack`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the forkify@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\Seinfeld\AppData\Roaming\npm-cache\_logs\2019-02-10T08_30_11_517Z-debug.log````

Anyone who knows the answer please tell me.
Thanks in advance

1 个答案:

答案 0 :(得分:1)

这实际上是webpack本身的错误。您可以降级到另一个版本。

这里是Issue

如果您使用纱线

添加到以下package.json

  "resolutions": {
    "ajv": "6.8.1"
  }

然后运行yarn install

如果您使用npm

npm uninstall ajv
npm install ajv@6.8.1