-
Notifications
You must be signed in to change notification settings - Fork 27k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error during build: Cannot read property 'file' of undefined #2531
Comments
The exact place where the error is thrown is: function getSource() {
var node = this.node;
if (node.end) {
return this.hub.file.code.slice(node.start, node.end); // <-- *here*
} else {
return "";
}
} I'm not familiar enough with Babel to know why |
Following who called function moduleExportsVisitor(path, opts) {
if (path.get('left').getSource() !== 'module.exports') { // <-- *here*
return;
}
defaultExports(path, path.get('right'), opts);
};
As a try, I added a check for if (path.hub && path.get('left').getSource() !== 'module.exports') { Now the build completes. OK, getting closer to a solution.. |
@eliot-akira can I see an example of the source code that causes the failure? Or maybe can you submit a PR to styled-jsx with a failing test? |
OK, I will see if I can create a failing test case for styled-jsx. |
So I created a number of tests for styled-jsx, all of which passed. I tested named class export, importing a named class export, and also just the whole source file from the problematic build. Then, going back to the Next build process, I started removing parts of the source file where the error is happening. Remove, test, remove, test..until I narrowed it down to the smallest chunk that still fails to build: export default function fn() {
for (let i = 0; i < 1; i++) {
const g = () => {}
const b = () => g()
i = 2
}
} I also removed extraneous details like variable names and what the original function did. This chunk as a test for styled-jsx passes, and the transpiled snapshot looks good. The multiple occurrences of |
OK, I think I've found a way to reliably reproduce this error:
Strange thing about this chunk is that if I remove any one part of it, the build error is gone. |
Odd, do you have a custom |
It happens on a brand new project with no babel config. As additional info, the build completes if I move the variable declaration outside the let i
for (i=0; ... |
|
Here's an example I put together: https://github.com/eliot-akira/next-build-debug Edit: I meant |
@eliot-akira yeah thank you! My guess is that by the time we do the check if (path.get('left').getSource() !== 'module.exports') the ast has been transformed by another plugin already and since Instead of being lazy and checking for the source to be want to give it a try and see if that fixes it? |
I tried the MemberExpression visitor in place of ExportDefaultDeclaration visitor in It seems the issue is further up the build pipeline, and styled-jsx is receiving "corrupted" syntax tree..? Here's the stack trace:
|
You need to replace |
Ah OK, I didn't know what I was doing there. So I did as you suggested: replace 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 |
I tried the above changes in styled-jsx source, and it fails 4 tests with |
Awesome, thank you for your collaboration! I can put together a patch in the following days, but if that's urgent feel free to submit a PR to styled-jsx. One thing to check before using my proposed fix is that there aren't edge cases and my code doesn't break other kind of btw |
Yes I noticed that mistake.. It works when passing parentPath. If I add It's not urgent, as I found a workaround for now in the problematic source file - to declare the variable before the Thank you for looking into it, I'm a big fan of Zeit and Next.js. |
Seems like this was fixed in styled-jsx |
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:
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
The text was updated successfully, but these errors were encountered: