webpack: TypeError: Cannot read property 'jsonData' of undefined

Please excuse that the bug report is quite short. I don’t have time to debug the problem myself today. Since the bug doesn’t come from other dependencies according to the stacktrace and the only change since the last usage is in the webpack version, I post the bug report anyway.

Bug report

What is the current behavior?

The build process crashes when watching for changes. The first build works fine, on saving a file, the process throws the folloging error.

let data = module.buildInfo.jsonData;
                            ^

TypeError: Cannot read property 'jsonData' of undefined
    at JsonGenerator.getSize (./node_modules/webpack/lib/json/JsonGenerator.js:119:31)
    at NormalModule.size (./node_modules/webpack/lib/NormalModule.js:1224:43)
    at NormalModule.cleanupForCache (./node_modules/webpack/lib/NormalModule.js:364:9)
    at NormalModuleFactory.cleanupForCache (./node_modules/webpack/lib/NormalModuleFactory.js:670:11)
    at Compiler._cleanupLastNormalModuleFactory (./node_modules/webpack/lib/Compiler.js:383:34)
    at Compiler.createNormalModuleFactory (./node_modules/webpack/lib/Compiler.js:1049:8)
    at Compiler.newCompilationParams (./node_modules/webpack/lib/Compiler.js:1071:30)
    at Compiler.compile (./node_modules/webpack/lib/Compiler.js:1082:23)
    at ./node_modules/webpack/lib/Watching.js:188:19
    at Hook.eval [as callAsync] (eval at create (./node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)

If the current behavior is a bug, please provide the steps to reproduce.

I will update the instructions to reproduce the error next week if necessary.

What is the expected behavior?

module.buildInfo seems to be undefined, although it shouldn’t be. When I replace the line with let data = module?.buildInfo?.jsonData; it works fine but I don’t think this would be a good solution.

Other relevant information: webpack version: 5.42.0 throws the error. 5.41.0 seems to be working Node.js version: v16.4.0, v12.x of my coworker didn’t work aswell Operating System: Windows Additional tools: Custom CLI with embedded webpack.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 31
  • Comments: 20 (5 by maintainers)

Commits related to this issue

Most upvoted comments

We will fix it in near future, sorry

Critical

While waiting…

I did a little package.json hack to force an older webpack version:

"scripts": {
  "preinstall": "npx npm-force-resolutions",
},
"devDependencies": {
  ...
},
"resolutions": {
  "webpack": "5.40.0"
},

Then run npm i

I had this problem just now, deps. is

@pmmmwh/react-refresh-webpack-plugin”: “^0.4.3”, “react-refresh”: “^0.10.0”, “webpack”: “^5.42.0”, “webpack-dev-server”: “^3.11.2”,

simple page is work fine , but when real project building process will crashes.

first building is work fine , second time is crashed

  • Webpack Version: 5.42.0
  • Node Version (node -v): v14.17.0
  • NPM Version (npm -v): 6.14.13
  • OS: Windows 10 20H2 (Build 19042.1052)

I’m having this bug, too. Here are some information from my side. Maybe it helps to find the issue. This is the error I get, when it happens:

D:\Files\Projects\PHP\eventplanner\node_modules\webpack\lib\json\JsonGenerator.js:119 let data = module.buildInfo.jsonData; ^

TypeError: Cannot read property ‘jsonData’ of undefined at JsonGenerator.getSize (D:\Files\Projects\PHP\eventplanner\node_modules\webpack\lib\json\JsonGenerator.js:119:31) at NormalModule.size (D:\Files\Projects\PHP\eventplanner\node_modules\webpack\lib\NormalModule.js:1224:43) at NormalModule.cleanupForCache (D:\Files\Projects\PHP\eventplanner\node_modules\webpack\lib\NormalModule.js:364:9) at NormalModuleFactory.cleanupForCache (D:\Files\Projects\PHP\eventplanner\node_modules\webpack\lib\NormalModuleFactory.js:670:11)
at Compiler._cleanupLastNormalModuleFactory (D:\Files\Projects\PHP\eventplanner\node_modules\webpack\lib\Compiler.js:383:34) at Compiler.createNormalModuleFactory (D:\Files\Projects\PHP\eventplanner\node_modules\webpack\lib\Compiler.js:1049:8) at Compiler.newCompilationParams (D:\Files\Projects\PHP\eventplanner\node_modules\webpack\lib\Compiler.js:1071:30) at Compiler.compile (D:\Files\Projects\PHP\eventplanner\node_modules\webpack\lib\Compiler.js:1082:23) at D:\Files\Projects\PHP\eventplanner\node_modules\webpack\lib\Watching.js:188:19 at Hook.eval [as callAsync] (eval at create (D:\Files\Projects\PHP\eventplanner\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:22:1) npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! eventplanner@1.0.0 watch: mix watch npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the eventplanner@1.0.0 watch 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\dneet\AppData\Roaming\npm-cache_logs\2021-07-04T19_15_00_411Z-debug.log

This is the content of the file 2021-07-04T19_15_00_411Z-debug.log:

0 info it worked if it ends with ok 1 verbose cli [ 1 verbose cli ‘C:\Program Files (x86)\nodejs\node.exe’, 1 verbose cli ‘C:\Program Files (x86)\nodejs\node_modules\npm\bin\npm-cli.js’, 1 verbose cli ‘run’, 1 verbose cli ‘watch’ 1 verbose cli ] 2 info using npm@6.14.13 3 info using node@v14.17.0 4 verbose run-script [ ‘prewatch’, ‘watch’, ‘postwatch’ ] 5 info lifecycle eventplanner@1.0.0~prewatch: eventplanner@1.0.0 6 info lifecycle eventplanner@1.0.0~watch: eventplanner@1.0.0 7 verbose lifecycle eventplanner@1.0.0~watch: unsafe-perm in lifecycle true 8 verbose lifecycle eventplanner@1.0.0~watch: PATH: C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;D:\Files\Projects\PHP\eventplanner\node_modules.bin;C:\Python39\Scripts;C:\Python39;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files\Microsoft\Web Platform Installer;C:\Program Files (x86)\nodejs;C:\ProgramData\chocolatey\bin;C:\Program Files (x86)\php\v7.4;C:\ProgramData\ComposerSetup\bin;C:\Program Files\PuTTY;C:\Program Files\Git\cmd;C:\Program Files (x86)\GitExtensions;C:\Program Files\MySQL\MySQL Shell 8.0\bin;C:\Users\dneet\AppData\Local\Microsoft\WindowsApps;;C:\Users\dneet\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\dneet\AppData\Roaming\npm;C:\Users\dneet\AppData\Roaming\Composer\vendor\bin;D:\Programme\texlive\2021\bin\win32 9 verbose lifecycle eventplanner@1.0.0~watch: CWD: D:\Files\Projects\PHP\eventplanner 10 silly lifecycle eventplanner@1.0.0~watch: Args: [ ‘/d /s /c’, ‘mix watch’ ] 11 silly lifecycle eventplanner@1.0.0~watch: Returned: code: 1 signal: null 12 info lifecycle eventplanner@1.0.0~watch: Failed to exec watch script 13 verbose stack Error: eventplanner@1.0.0 watch: mix watch 13 verbose stack Exit status 1 13 verbose stack at EventEmitter.<anonymous> (C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:332:16) 13 verbose stack at EventEmitter.emit (events.js:376:20) 13 verbose stack at ChildProcess.<anonymous> (C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14) 13 verbose stack at ChildProcess.emit (events.js:376:20) 13 verbose stack at maybeClose (internal/child_process.js:1055:16) 13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5) 14 verbose pkgid eventplanner@1.0.0 15 verbose cwd D:\Files\Projects\PHP\eventplanner 16 verbose Windows_NT 10.0.19042 17 verbose argv “C:\Program Files (x86)\nodejs\node.exe” “C:\Program Files (x86)\nodejs\node_modules\npm\bin\npm-cli.js” “run” “watch” 18 verbose node v14.17.0 19 verbose npm v6.14.13 20 error code ELIFECYCLE 21 error errno 1 22 error eventplanner@1.0.0 watch: mix watch 22 error Exit status 1 23 error Failed at the eventplanner@1.0.0 watch script. 23 error This is probably not a problem with npm. There is likely additional logging output above. 24 verbose exit [ 1, true ]

Actually it happens every second edit of my code.

I have the same issue, when importing avj (json-schema library) and running webpack with --watch. The first build runs normally without errors, but subsequent builds (typically the second one after a changing a file) crashes webpack with the same stacktrace as above.

Setting cache: false on webpack.config.js resolves the issue.

@raduchiriac @dgb23 This worked. I don’t have a webpack.config.js for Storybook, but I made an entry in main.js in the webpackFinal method setting config.cache = false; And it works. Thanks for this. I spent a lot of time trying various suggestions and only this one worked.

Running into the same issue, switching to 5.41.0 doesn’t resolve issue.

node version v12.x Operating System: osx

Works when building to a system module directly from webpack compiler, but fails in fresh storybook running webpack 5

config.cache = false;

This worked. Thanks @dgb23 & @TerrySlack

.storybook/main.js

module.exports = {
  ...
  webpackFinal: async (config, { configType }) => {
    ...

    config.cache = false
    return config
  },
}

@alexander-akait There is my reproduction repo for the issue.

I managed to narrow down the bug to using only one external package ajv with a specific version