Search code examples
node.jsnpmwebpackcreate-react-app

After ejecting create-react-app to update packages, "webpack is not a function"


Using an older version create-react-app on an experimental boilerplate project, I needed to update the packages to proceed. I thought the best way to do this was to eject the create-react-app, but now the whole thing won't run. This is the output after Nodemon:

[1] Failed to compile.
[1] 
[1] webpack is not a function
[1] 
[1] npm ERR! code ELIFECYCLE
[1] npm ERR! errno 1
[1] npm ERR! [email protected] start: `node scripts/start.js`
[1] npm ERR! Exit status 1
[1] npm ERR! 
npm ERR! Failed at the [email protected] start script.
[1] npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
[1] 
[1] npm ERR! A complete log of this run can be found in:
[1] npm ERR!     /Users/gabrielkunkel/.npm/_logs/2019-11-20T23_19_58_956Z-debug.log

If I search the complete log, webpack doesn't show up at all. I wish I could narrow this down to something just useful.

0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli   '/Users/gabrielkunkel/.nvm/versions/node/v12.8.1/bin/node',
1 verbose cli   '/Users/gabrielkunkel/.nvm/versions/node/v12.8.1/bin/npm',
1 verbose cli   'start'
1 verbose cli ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle [email protected]~prestart: [email protected]
6 info lifecycle [email protected]~start: [email protected]
7 verbose lifecycle [email protected]~start: unsafe-perm in lifecycle true
8 verbose lifecycle [email protected]~start: PATH: /Users/gabrielkunkel/.nvm/versions/node/v12.8.1/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/gabrielkunkel/Documents/DevCodeCamp/Capstone/kunkl-project/client/node_modules/.bin:/Users/gabrielkunkel/.nvm/versions/node/v12.8.1/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/gabrielkunkel/Documents/DevCodeCamp/Capstone/kunkl-project/node_modules/.bin:/Users/gabrielkunkel/.nvm/versions/node/v12.8.1/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/Library/Frameworks/Python.framework/Versions/3.5/bin:/Library/Frameworks/Python.framework/Versions/3.4/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/share/dotnet:~/.dotnet/tools:/usr/local/git/bin:/usr/local/MacGPG2/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Users/gabrielkunkel/.nvm/versions/node/v12.8.1/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/Library/Frameworks/Python.framework/Versions/3.5/bin:/Library/Frameworks/Python.framework/Versions/3.4/bin:/Users/gabrielkunkel/.rvm/bin:/Users/gabrielkunkel/.rvm/bin
9 verbose lifecycle [email protected]~start: CWD: /Users/gabrielkunkel/Documents/DevCodeCamp/Capstone/kunkl-project/client
10 silly lifecycle [email protected]~start: Args: [ '-c', 'node scripts/start.js' ]
11 silly lifecycle [email protected]~start: Returned: code: 1  signal: null
12 info lifecycle [email protected]~start: Failed to exec start script
13 verbose stack Error: [email protected] start: `node scripts/start.js`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/Users/gabrielkunkel/.nvm/versions/node/v12.8.1/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:203:13)
13 verbose stack     at ChildProcess.<anonymous> (/Users/gabrielkunkel/.nvm/versions/node/v12.8.1/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:203:13)
13 verbose stack     at maybeClose (internal/child_process.js:1021:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
14 verbose pkgid [email protected]
15 verbose cwd /Users/gabrielkunkel/Documents/DevCodeCamp/Capstone/kunkl-project/client
16 verbose Darwin 16.7.0
17 verbose argv "/Users/gabrielkunkel/.nvm/versions/node/v12.8.1/bin/node" "/Users/gabrielkunkel/.nvm/versions/node/v12.8.1/bin/npm" "start"
18 verbose node v12.8.1
19 verbose npm  v6.13.1
20 error code ELIFECYCLE
21 error errno 1
22 error [email protected] start: `node scripts/start.js`
22 error Exit status 1
23 error Failed at the [email protected] start script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

I tried cleaning out the node_modules and re-installing them off a suggestion here, with a slightly different problem. I even tried installing webpack globally.

I'm hoping to just fix some small thing and keep going or at least understand why it can't run webpack. As it is, I'm going to be saving all the files and rerun create-react-app unless you can help me.


Solution

  • Your best bet is to build a new create-react-app in a separate folder then to run npm run eject. You then use version control to see the differences in the package.json as well as the config and script folders/files. Update your node modules to match those of the newly created create-react-app and copy/paste the config files.