Babel 7: TypeError: Cannot read property 'replace' of undefined
See original GitHub issueTrying to move to babel 7…
- “webpack”: “^4.16.5”,
- “@babel/core”: “^7.0.0-rc.1”,
- “babel-plugin-dynamic-import-node”: “^2.0.0”,
- “babel-plugin-universal-import”: “faceyspacey/babel-plugin-universal-import#webpack-4”,
- “babel-preset-react-app”: “^4.0.0-next.66cc7a90”, …
The build process interrupts with an error shown below (see trace).
trace
/home/anton/Documents/workspace-sts/nodejs-spring-cloud-app-boilerplate/node_modules/babel-plugin-universal-import/index.js:24
return baseDir.replace(/^[./]+|(\.js$)/g, '')
^
TypeError: Cannot read property 'replace' of undefined
at trimChunkNameBaseDir (/home/anton/Documents/workspace-sts/nodejs-spring-cloud-app-boilerplate/node_modules/babel-plugin-universal-import/index.js:24:18)
at getMagicCommentChunkName (/home/anton/Documents/workspace-sts/nodejs-spring-cloud-app-boilerplate/node_modules/babel-plugin-universal-import/index.js:64:23)
at checkForNestedChunkName (/home/anton/Documents/workspace-sts/nodejs-spring-cloud-app-boilerplate/node_modules/babel-plugin-universal-import/index.js:164:30)
at PluginPass.Import (/home/anton/Documents/workspace-sts/nodejs-spring-cloud-app-boilerplate/node_modules/babel-plugin-universal-import/index.js:190:33)
at newFn (/home/anton/Documents/workspace-sts/nodejs-spring-cloud-app-boilerplate/node_modules/@babel/core/node_modules/@babel/traverse/lib/visitors.js:193:21)
at NodePath._call (/home/anton/Documents/workspace-sts/nodejs-spring-cloud-app-boilerplate/node_modules/@babel/core/node_modules/@babel/traverse/lib/path/context.js:53:20)
at NodePath.call (/home/anton/Documents/workspace-sts/nodejs-spring-cloud-app-boilerplate/node_modules/@babel/core/node_modules/@babel/traverse/lib/path/context.js:40:17)
at NodePath.visit (/home/anton/Documents/workspace-sts/nodejs-spring-cloud-app-boilerplate/node_modules/@babel/core/node_modules/@babel/traverse/lib/path/context.js:88:12)
at TraversalContext.visitQueue (/home/anton/Documents/workspace-sts/nodejs-spring-cloud-app-boilerplate/node_modules/@babel/core/node_modules/@babel/traverse/lib/context.js:118:16)
at TraversalContext.visitSingle (/home/anton/Documents/workspace-sts/nodejs-spring-cloud-app-boilerplate/node_modules/@babel/core/node_modules/@babel/traverse/lib/context.js:90:19)
error Command failed with exit code 1.
The components are kinda:
component: universal(props => import(/* webpackChunkName: 'components-Home' */ /* webpackMode: "lazy" */ '../components/Home'),
{
resolve: props => require.resolveWeak('../components/Home'),
chunkName: 'components-Home'
}),
loadData: async (store, params) => {
if(store) {
store.dispatch(actions.setMessage('Hi, I\'m from server!'))
}
return Promise.resolve()
},
When I switch the using of UC in code off and start project with only empty wrappers around the absent components, project is been built successfully.
Do I wrong smth or is it a bug?
PS The components like above are working "somehow" with babel 6. "somehow" - yep, but do work.
Issue Analytics
- State:
- Created 5 years ago
- Comments:53
Top Results From Across the Web
js: TypeError: Cannot read property 'replace' of undefined ...
I wanted to replace /\r?\n|\r/g with empty string but got a type error "Cannot read property 'replace' of undefined".
Read more >[SOLVED] Cannot Read Property 'replace' of Undefined in JS
To fix the “cannot read property 'replace' of undefined” error, perform an undefined check on the variable before calling the replace() method ......
Read more >TypeError: Cannot read property 'replace' of Undefined in JS
The "Cannot read property 'replace' of undefined" error occurs when calling the replace() method on a variable that stores an undefined value.
Read more >[Solved]-Cannot read property 'replace ' of undefined-Reactjs
Coding example for the question Cannot read property 'replace ' of undefined-Reactjs.
Read more >Upgrade to Babel 7 (API)
Dropped use of add-module-exports plugin on Babel packages. This had to be used earlier to prevent a breaking change with our exports. If...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
So this issue only happens when combined with
dynamic-import-node
. Here is a repo of the issue: https://gist.github.com/franjohn21/f9ed2e389f5070826343d38afed08a28npx https://gist.github.com/franjohn21/f9ed2e389f5070826343d38afed08a28
to see the error:Zack, have you and James any plans on rewrite docs? Imho, it needs to be more structured. Your email doesn’t work, probably… I tried to write you with no luck.