question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error during build: Cannot read property 'file' of undefined

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:19 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
eliot-akiracommented, Jul 12, 2017

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.

1reaction
eliot-akiracommented, Jul 12, 2017

Ah OK, I didn’t know what I was doing there. So I did as you suggested: replace AssignmentExpression with MemberExpression in babel.js, and then modified moduleExportsVisitor in babel-external.js to the following:

function moduleExportsVisitor(path, opts) {
  if (path.get('object').node.name !== 'module') {
    return
  }
  if (path.get('property').node.name !== 'exports') {
    return
  }
  console.log('yep module export')
  const parentPath = path.parentPath
  defaultExports(path, parentPath, opts)
}

Yes, the build completes successfully. I also tried defining module.exports in the problematic snippet, and it recognizes it.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found