Error during build: Cannot read property 'file' of undefined
See original GitHub issueI’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 |
Issue Analytics
- State:
- Created 6 years ago
- Comments:19 (8 by maintainers)
Top Results From Across the Web
Node.js TypeError: Cannot read property 'file' of undefined
You are using upload.single , which you should use req.file not req.files . To upload multiple files, use upload.array .
Read more >Error during build: Cannot read property 'file' of undefined #2531
I'm stuck on an odd error during build, where a certain source file is unable to be transpiled. The file in question just...
Read more >Cannot Read Property of Undefined in JavaScript - Rollbar
TypeError : Cannot read property of undefined occurs when a property is read or a function is called on an undefined variable.
Read more >cannot read properties of undefined (reading 'filename') multer
It looks like the error handling isn't right, during file saving in particular; in which the resulting errors are not being handled. For...
Read more >VScode error: Cannot read property 'file' of undefined - Tooling
Hi guys, I'm using VScode + julia extensions. Normally, when I apply ⇧(shift)+enter on a line of code in a .jl file, it...
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
Yes I noticed that mistake… It works when passing parentPath.
If I add
if (!path.get('object').node) return
then 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
for
loop - 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
AssignmentExpression
withMemberExpression
inbabel.js
, and then modifiedmoduleExportsVisitor
inbabel-external.js
to the following:Yes, the build completes successfully. I also tried defining
module.exports
in the problematic snippet, and it recognizes it.