next.js: Error during build: Cannot read property 'file' of undefined
I’m stuck on an odd error during build, where a certain source file is unable to be transpiled. The file in question just exports a named class: export class ...
The issue seems to be caused by styled-jsx and its moduleExportsVisitor. The file where the error occurs does not use React or styled-jsx.
Any advice/help would be appreciated. For now, I’m working around it by creating a separate build for that module without going through the Next build pipeline. Here’s the stack trace:
Module build failed: TypeError: ~/dev/mooz/vex/src/accidental.js: Cannot read property 'file' of undefined
at NodePath.getSource (~/dev/node_modules/babel-traverse/lib/path/introspection.js:193:20)
at moduleExportsVisitor (~/dev/node_modules/styled-jsx/dist/babel-external.js:171:24)
at callExternalVisitor (~/dev/node_modules/styled-jsx/dist/babel.js:346:3)
at PluginPass.AssignmentExpression (~/dev/node_modules/styled-jsx/dist/babel.js:308:9)
at newFn (~/dev/node_modules/babel-traverse/lib/visitors.js:276:21)
at NodePath._call (~/dev/node_modules/babel-traverse/lib/path/context.js:76:18)
at NodePath.call (~/dev/node_modules/babel-traverse/lib/path/context.js:48:17)
at NodePath.visit (~/dev/node_modules/babel-traverse/lib/path/context.js:105:12)
at TraversalContext.visitQueue (~/dev/node_modules/babel-traverse/lib/context.js:150:16)
at TraversalContext.visitSingle (~/dev/node_modules/babel-traverse/lib/context.js:108:19)
at TraversalContext.visit (~/dev/node_modules/babel-traverse/lib/context.js:192:19)
at Function.traverse.node (~/dev/node_modules/babel-traverse/lib/index.js:114:17)
- I have searched the issues of this repository and believe that this is not a duplicate.
Expected Behavior
The build task completes successfully.
Current Behavior
The build task fails with an error mentioned in summary.
Steps to Reproduce
Unknown
Your Environment
| Tech | Version |
|---|---|
| next | @beta |
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 19 (19 by maintainers)
Commits related to this issue
- Properly detect module.exports (#267) Fixes zeit/next.js#2531 — committed to vercel/styled-jsx by giuseppeg 9 years ago
- Properly detect module.exports (#267) Fixes zeit/next.js#2531 — committed to wroy7860/styled-jsx-github-React-and-node by wroy7860 9 years ago
- Properly detect module.exports (#267) Fixes zeit/next.js#2531 — committed to ericbrown2716/styled-jsx-react-repo by ericbrown2716 9 years ago
- Properly detect module.exports (#267) Fixes zeit/next.js#2531 — committed to renawolford6/styled-jsx-development-react-and-node by deleted user 9 years ago
- Properly detect module.exports (#267) Fixes zeit/next.js#2531 — committed to johnfrench3/styled-jsx-Build-React by deleted user 9 years ago
- Properly detect module.exports (#267) Fixes zeit/next.js#2531 — committed to JiachenSmith/styled-jsx by giuseppeg 9 years ago
Yes I noticed that mistake… It works when passing parentPath.
If I add
if (!path.get('object').node) returnthen all tests pass except 1.It’s not urgent, as I found a workaround for now in the problematic source file - to declare the variable before the
forloop - so it compiles.Thank you for looking into it, I’m a big fan of Zeit and Next.js.
Ah OK, I didn’t know what I was doing there. So I did as you suggested: replace
AssignmentExpressionwithMemberExpressioninbabel.js, and then modifiedmoduleExportsVisitorinbabel-external.jsto the following:Yes, the build completes successfully. I also tried defining
module.exportsin the problematic snippet, and it recognizes it.OK, I will see if I can create a failing test case for styled-jsx.