Issue 1:
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 2:
Feature request

Is your feature request related to a problem? Please describe.

All the components of the current app I am working on will be loaded as npm modules. This means that about 30 components will be worked on at the same time. Therefore it is critical for me to be able to link them locally while I am developing on them. I have not been able to get the packages to load with next without using a custom next.config.js.

This is the error I get:

Module parse failed: Unexpected token (15:12) You may need an appropriate loader to handle this file type.

Describe the solution you'd like

I have managed to get it to work by using require.resolve() on all loaders in the webpack config.

This is the next.config.js I am using (running on: 6.0.4-canary.8):

const withTypescript = require('@zeit/next-typescript');

function resolveLoader(loader) {
try {
loader = require.resolve(__dirname + '/node_modules/next/dist/server/build/loaders/' + loader);
} catch(error) {
try {
loader = require.resolve(loader);
} catch(error) {
//Ignore error
}
}
return loader;
}

module.exports = withTypescript({
webpack(config, options) {
for (const rule of config.module.rules) {
rule.exclude = /node_modules\/(?!(@my-scope)\/).*/;
delete rule.include;
rule.loader = resolveLoader(rule.loader);
if(Array.isArray(rule.use)) {
rule.use[0] = resolveLoader(rule.use[0]);
} else if(typeof rule.use === 'object' && rule.use.loader) {
rule.use.loader = resolveLoader(rule.use.loader);
}
}

return config;
}
});

Describe alternatives you've considered

Make resolvement of loaders an option. Perhaps by providing a function like: withResolvedLoaders()

Make it permanent if this doesn't cause issues with other functionality like .babelrc

Inform people about the issue and provide with a solution for it in the documentation

I believe that option 1 would be the easiest alternative and least error prone.

Additional context