-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Runtime error when loading mjs files #8655
Comments
This sounds like a reasonable change to add to core. Can you create a reproduction site that currently doesn't work? |
@corydeppen thanks for the repro and more detail on the fix! This is a great issue that someone in the community (or yourself if you're interested 😄) could tackle. For other coming here, this will involve the following changes: Updating our webpack.config.js and rules in webpack-utils.js to default to adding the |
I 100% agree with this pr. ran into a similar issue at work about a week ago. we use NextJS for a lot of the live projects. next recently released version 7 -- and it now uses babel 7 and webpack 4 under the hood. First thing noticed when upgrading to Next7:
{
test: /\.mjs$/,
include: /node_modules/,
type: 'javascript/auto'
} config.resolve.extensions = ['.mjs', '.tsx', '.ts', '.js', '.jsx', '.json'] Here is a ticket opened up in the next codebase, along with the same solution. |
deals with issues: - Fixes #8655 - other various `.mjs` issues after the switch to webpack 4 Add webpack rule to explicitly state that `.mjs` files are to be loaded in with the default webpack 4 js loader. Comments also left for future references. @KyleAMathews 's pr (https://github.com/gatsbyjs/gatsby/pull/8327/files) was correct to add the extensions -- but `.mjs` needs to be before the `.js` extension. Looks like someone changed it in a PR afterwards. In any case, this is half of the solution. We need to explicitly state what loader webpack should use when resolving these files.
Description
I've read through several recent discussions about supporting
mjs
files and I see #8327 was merged to include the extension, however I continue to see the originalrequire is not defined
runtime error after adding the change to include the extension. From what I've seen in my app and in several repos (e.g. aws-amplify/amplify-js#686, facebook/create-react-app#5151), the test formjs
still needs to be added to the webpack JS loader rules.Steps to reproduce
My app is based on the using-multiple-providers example, along with the gatsby-source-graphql plugin.
The following custom webpack config allows the page to load as expected:
Expected result
Should not see a runtime error when using packages that include
mjs
files.Actual result
Environment
The text was updated successfully, but these errors were encountered: