TehShrike / deepmerge

A library for deep (recursive) merging of Javascript objects
MIT License
2.75k stars 216 forks source link

TypeError: Cannot convert undefined or null to object? #135

Closed Wonkasho closed 5 years ago

Wonkasho commented 5 years ago

In a laravel 5.6/reactjs app, after upgrading laravel-mix from version 2 to "laravel-mix": "^4.0.14", when I run npm run development I get the below error (the error seems to be tied to this package I think, since it shows deepmerge):

> npm run development
> cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js

/home/mydomain.com/node_modules/webpack-cli/bin/cli.js:235
                throw err;
                ^

TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at mergeObject (/home/mydomain.com/node_modules/deepmerge/dist/umd.js:55:9)
    at deepmerge (/home/mydomain.com/node_modules/deepmerge/dist/umd.js:79:10)
    at reduce (/home/mydomain.com/node_modules/babel-merge/dist/index.js:30:44)
    at Array.reduce (<anonymous>)
    at mergeArray (/home/mydomain.com/node_modules/babel-merge/dist/index.js:20:36)
    at babelMerge (/home/mydomain.com/node_modules/babel-merge/dist/index.js:40:19)
    at values.reduce (/home/mydomain.com/node_modules/babel-merge/dist/index.js:60:26)
    at Array.reduce (<anonymous>)
    at Function.value (/home/mydomain.com/node_modules/babel-merge/dist/index.js:58:49)
    at Function.generate (/home/mydomain.com/node_modules/laravel-mix/src/BabelConfig.js:11:22)
    at Object.babel (/home/mydomain.com/node_modules/laravel-mix/src/config.js:121:45)
    at React.webpackRules (/home/mydomain.com/node_modules/laravel-mix/src/components/JavaScript.js:76:41)
    at ComponentFactory.applyRules (/home/mydomain.com/node_modules/laravel-mix/src/components/ComponentFactory.js:155:23)
    at Mix.listen.rules (/home/mydomain.com/node_modules/laravel-mix/src/components/ComponentFactory.js:66:48)
    at events.(anonymous function).forEach.handler (/home/mydomain.com/node_modules/laravel-mix/src/Dispatcher.js:34:47)
    at Array.forEach (<anonymous>)
    at Dispatcher.fire (/home/mydomain.com/node_modules/laravel-mix/src/Dispatcher.js:34:28)
    at Mix.dispatch (/home/mydomain.com/node_modules/laravel-mix/src/Mix.js:119:25)
    at WebpackConfig.buildRules (/home/mydomain.com/node_modules/laravel-mix/src/builder/WebpackConfig.js:83:13)
    at WebpackConfig.build (/home/mydomain.com/node_modules/laravel-mix/src/builder/WebpackConfig.js:23:14)
    at Object.<anonymous> (/home/mydomain.com/node_modules/laravel-mix/setup/webpack.config.js:29:38)
    at Module._compile (/home/mydomain.com/node_modules/v8-compile-cache/v8-compile-cache.js:178:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Module.require (module.js:597:17)
    at require (/home/mydomain.com/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
    at WEBPACK_OPTIONS (/home/mydomain.com/node_modules/webpack-cli/bin/convert-argv.js:115:13)
    at requireConfig (/home/mydomain.com/node_modules/webpack-cli/bin/convert-argv.js:117:6)
    at /home/mydomain.com/node_modules/webpack-cli/bin/convert-argv.js:124:17
    at Array.forEach (<anonymous>)
    at module.exports (/home/mydomain.com/node_modules/webpack-cli/bin/convert-argv.js:122:15)
    at yargs.parse (/home/mydomain.com/node_modules/webpack-cli/bin/cli.js:232:39)
    at Object.parse (/home/mydomain.com/node_modules/webpack-cli/node_modules/yargs/yargs.js:567:18)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ development: `cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the @ development 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!     /home/.npm/_logs/2019-01-21T18_30_16_092Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ dev: `npm run development`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the @ 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!     /home/.npm/_logs/2019-01-21T18_30_16_106Z-debug.log

I tried for a whole day to fix it and can't figure out how to get past this error to compile successfully.

Any idea how to fix this error so we can compile the app?

TehShrike commented 5 years ago

What is the output of npm ls deepmerge?

TehShrike commented 5 years ago

From the stack trace, I would guess that either baseOptions or overrideOptions is undefined at this point: https://github.com/eliperelman/babel-merge/blob/master/src/index.js#L21-L25

Maybe look into laravel-mix/src/BabelConfig.js to try to figure out what options it's expecting to be defined that is currently undefined?

This is not an issue with deepmerge. deepmerge will throw an error if you pass null or undefined in as an argument.

Wonkasho commented 5 years ago

What is the output of npm ls deepmerge?

Thanks for your response, the output is:

└─┬ laravel-mix@4.0.14
  └─┬ babel-merge@2.0.1
    └── deepmerge@2.2.1

Thanks, I will check out laravel-mix/src/BabelConfig.js, to me it's very cryptic to point out the exact issue, and wasn't sure why this happened, but when I saw deepmerge in the error stack, I had to post here.