-
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
Build fails after with "Unexpected token" in async-requires
after upgrade to 2.0.84
#11198
Comments
I'm experiencing a similar error after upgrading from In my case, error Generating JavaScript bundles failed
Error: ./.cache/async-requires.js 8:11
Module parse failed: Unexpected token (8:11)
You may need an appropriate loader to handle this file type.
| exports.components = {
| "component---src-templates-template-js": function componentSrcTemplatesTemplateJs() {
> return import("/Users/michael/Sites/projects/gatsby-starter/src/templates/template.js"
| /* webpackChunkName: "component---src-templates-template-js" */ | );
@ ./.cache/production-app.js 18:0-45 21:23-36 26:23-36 or error Generating JavaScript bundles failed
Error: ./.cache/async-requires.js 8:11
Module parse failed: Unexpected token (8:11)
You may need an appropriate loader to handle this file type.
| exports.components = {
| "component---src-pages-404-js": function componentSrcPages404Js() {
> return import("/Users/michael/Sites/projects/gatsby-starter/src/pages/404.js"
| /* webpackChunkName: "component---src-pages-404-js" */
| );
@ ./.cache/production-app.js 18:0-45 21:23-36 26:23-36 Everything worked fine before upgrading |
I'm getting the same error using Gatsby v 2.0.55 where package-lock.json is disabled in .npmrc. The site is built from a clean workspace daily. One day it worked, the next it didn't. I'm guessing the error is related to some transient dependency which has changed. |
same issue when I upgrade |
Hi, chiming in to say that I am currently also experiencing this issue, but am struggling to build a minimal reproduction for it. Currently running an I'll keep digging around until I can find what's causing it or someone else figures it out. If I can get it isolated cleanly I'll post back here. Thanks! |
Same here! gatsby plugin offline version -> 2.0.21 Repository with this problem: there you go. |
Also can you list the installed dependencies with |
Bisecting might be helpful here too. I'll test the repo in a few minutes. Ok same error here. I'll bisect this. It seems it happens in all versions so it is a plugin or another dependency probably. |
I think I found the cause. I'll provide a patch and PR. |
@omrllm (a patch for gatsby 2.0.60) patch-package
--- a/node_modules/gatsby/dist/internal-plugins/query-runner/pages-writer.js
+++ b/node_modules/gatsby/dist/internal-plugins/query-runner/pages-writer.js
@@ -86,9 +86,9 @@ const preferDefault = m => m && m.default || m
let asyncRequires = `// prefer default export if available
const preferDefault = m => m && m.default || m
\n`;
- asyncRequires += `exports.components = {\n${components.map(c => ` "${c.componentChunkName}": () => import("${(0, _path.joinPath)(c.component)}" /* webpackChunkName: "${c.componentChunkName}" */)`).join(`,\n`)}
+ asyncRequires += `exports.components = {\n${components.map(c => ` "${c.componentChunkName}": () => require("${(0, _path.joinPath)(c.component)}" /* webpackChunkName: "${c.componentChunkName}" */)`).join(`,\n`)}
}\n\n`;
- asyncRequires += `exports.data = () => import("${(0, _path.joinPath)(program.directory, `.cache`, `data.json`)}")\n\n`;
+ asyncRequires += `exports.data = () => require("${(0, _path.joinPath)(program.directory, `.cache`, `data.json`)}")\n\n`;
const writeAndMove = (file, data) => {
const destination = (0, _path.joinPath)(program.directory, `.cache`, file);
|
By changing the |
Diff after the updater and a new build run @madelyneriksen |
patch-package
--- a/node_modules/gatsby/dist/internal-plugins/query-runner/pages-writer.js
+++ b/node_modules/gatsby/dist/internal-plugins/query-runner/pages-writer.js
@@ -88,9 +88,9 @@ const preferDefault = m => m && m.default || m
let asyncRequires = `// prefer default export if available
const preferDefault = m => m && m.default || m
\n`;
- asyncRequires += `exports.components = {\n${components.map(c => ` "${c.componentChunkName}": () => import("${(0, _path.joinPath)(c.component)}" /* webpackChunkName: "${c.componentChunkName}" */)`).join(`,\n`)}
+ asyncRequires += `exports.components = {\n${components.map(c => ` "${c.componentChunkName}": () => require("${(0, _path.joinPath)(c.component)}" /* webpackChunkName: "${c.componentChunkName}" */)`).join(`,\n`)}
}\n\n`;
- asyncRequires += `exports.data = () => import(/* webpackChunkName: "pages-manifest" */ "${(0, _path.joinPath)(program.directory, `.cache`, `data.json`)}")\n\n`;
+ asyncRequires += `exports.data = () => require(/* webpackChunkName: "pages-manifest" */ "${(0, _path.joinPath)(program.directory, `.cache`, `data.json`)}")\n\n`;
const writeAndMove = (file, data) => {
const destination = (0, _path.joinPath)(program.directory, `.cache`, file);
This should work for .98 |
Maybe I am on the wrong track, the change produces failing tests #11331 Not yet sure why. |
So it still doesn't work, right? |
The build script succeeds with my proposed change. But I'm not sure if this is the right solution. So please test and review it. |
Hm, or is it due to the new preset? Is the plugins array correct? Does the issue also happen in a fresh new Gatsby project and can it be reproduced with the CI tests? |
Please provide a list of the installed dependencies (before and after the update). |
@DanielRuf, I can't reproduce it I guess it was a fluke I am still getting the error. |
A workaround is to install the dependencies with Yarn instead of npm which seems to work after importing the npm lockfile. |
You can find my I still have the problem with gatsby 2.0.103 |
Did you try to install the dependencies with |
@cyrildurand |
I think this may be the issue: webpack/webpack#8656. Added: Symptoms match and timing fits, too. |
This addresses gatsbyjs#11198. There's a regression bug webpack/webpack#8656 affecting 4.29.0 through at least 4.29.3 which causes errors like this during `gatsby build`. Error: ./.cache/async-requires.js 8:11 Module parse failed: Unexpected token (8:11) You may need an appropriate loader to handle this file type. | exports.components = { | "component---frontend-components-main-js": function componentFrontendCompo nentsMainJs() { > return import("/home/circleci/project/frontend/components/main.js" | /* webpackChunkName: "component---frontend-components-main-js" */ | ); @ ./.cache/production-app.js 18:0-45 21:23-36 26:23-36
This addresses gatsbyjs#11198. There's a regression bug webpack/webpack#8656 affecting 4.29.0 through at least 4.29.3 which causes errors like this during `gatsby build`. Error: ./.cache/async-requires.js 8:11 Module parse failed: Unexpected token (8:11) You may need an appropriate loader to handle this file type. | exports.components = { | "component---frontend-components-main-js": function componentFrontendCompo nentsMainJs() { > return import("/home/circleci/project/frontend/components/main.js" | /* webpackChunkName: "component---frontend-components-main-js" */ | ); @ ./.cache/production-app.js 18:0-45 21:23-36 26:23-36
@paulmelnikow good catch. And this is why I recommend using CJS if we do not have to use ESM - it is still not 100% reliable in bundlers. And the other way should still work. So pinning webpack in the root package.json should work? |
And this js also why SemVer in the JS ecosystem is totally broken imho. The automatic updates of (deep) deps because the lockfiles only work in the root level. |
To be clear, webpack/webpack#8656 (comment) I can reproduce this (another reason why we still use yarn at work). |
To be exact, it is a npm issue. https://npm.community/t/packages-with-peerdependencies-are-incorrectly-hoisted/4794/4 https://npm.community/t/release-npm-6-8-0-next-0/5058 Solution: install latest npm release. |
I'm not sure I agree with that assessment. This may manifest in npm and not yarn due to differences in the way resolution takes place, however 4.29.3 is a perfectly correct version to install when a package has declared a dependency on ^4.12.0. That is what the caret means. If Gatsby wants to lock a specific version it is welcome to do so, and in that case npm will honor it. Webpack is a dependency of Gatsby, not a peer dependency. |
The issue is was the hoisting in npm (different in Yarn) and that |
I feel like I need you to explain that better. I skimmed those threads but don’t see how any it applies here. I don’t know what is causing the bug in Webpack; however if we agree Gatsby shouldn’t use 4.29.3, the caret dependency needs to be changed. |
It works with yarn, it is just an issue with npm, in combination with specific dependencies and the deptree calculation. See the PR of Tobias. |
Aiiiee gotcha. It's that peer dependencies bug in npm which is what's causing webpack 4.29 not to work correctly. What we can prevent is the installation of webpack 4.29. And I'm not sure there is an easy way of an end user locking the webpack version. npm doesn't provide a way to do it, so users would have to use something like the third-party tool npm-force-resolutions. See npm/cli#152; it doesn't look like we can expect a quick resolution. |
…11640) ## Description This addresses #11198. There's a regression bug webpack/webpack#8656 affecting 4.29.0 through at least 4.29.3 which causes errors like this during `gatsby build`. Error: ./.cache/async-requires.js 8:11 Module parse failed: Unexpected token (8:11) You may need an appropriate loader to handle this file type. | exports.components = { | "component---frontend-components-main-js": function componentFrontendCompo nentsMainJs() { > return import("/home/circleci/project/frontend/components/main.js" | /* webpackChunkName: "component---frontend-components-main-js" */ | ); @ ./.cache/production-app.js 18:0-45 21:23-36 26:23-36 <!-- Have any questions? Check out the contributing docs at https://gatsby.app/contribute, or ask in this Pull Request and a Gatsby maintainer will be happy to help :) --> ## Related Issues - Addresses #11198 - Related to webpack/webpack#8656
Now that 2.0.118 ships a band-aid, npm users should be okay, and obviously can’t use webpack 4.29.x regardless. Am I right that yarn users can use |
@paulmelnikow correct - but really shouldn't be necessary and I'm not sure there's a particular necessary benefit in doing so. We'll update the pinned dependency as soon as we are able to (following the npm issue now), so it should be but a blip for Thanks for the fix! Now I think I can close this out :) |
Confirmed fixed with the 2.0.118 release! |
This was amazing to follow. Thank you all for the amazing work! |
…atsbyjs#11640) ## Description This addresses gatsbyjs#11198. There's a regression bug webpack/webpack#8656 affecting 4.29.0 through at least 4.29.3 which causes errors like this during `gatsby build`. Error: ./.cache/async-requires.js 8:11 Module parse failed: Unexpected token (8:11) You may need an appropriate loader to handle this file type. | exports.components = { | "component---frontend-components-main-js": function componentFrontendCompo nentsMainJs() { > return import("/home/circleci/project/frontend/components/main.js" | /* webpackChunkName: "component---frontend-components-main-js" */ | ); @ ./.cache/production-app.js 18:0-45 21:23-36 26:23-36 <!-- Have any questions? Check out the contributing docs at https://gatsby.app/contribute, or ask in this Pull Request and a Gatsby maintainer will be happy to help :) --> ## Related Issues - Addresses gatsbyjs#11198 - Related to webpack/webpack#8656
Hey all! I wonder if you guys could give |
Hi @wardpeet! Thanks for reaching out. I created a branch here: badges/shields#3572 It looks like it's still an issue: https://circleci.com/gh/badges/shields/57401 Steps to reproduce locally would be to clone that branch and run |
@paulmelnikow thanks so much! Could you also tell me what node & npm version you using so I can run it with your setup as well in case it works for me. |
This is what I've got locally:
In CI it's also happening in Node 8 (not sure the exact npm version). The problem is reproducible in both environments. Thanks for looking into it! |
Description
Running
rm -rf .cache && rm -rf public && gatsby-build
works fine under 2.0.83. After upgrading to 2.0.84, an error is thrown, aborting the build.Steps to reproduce
The only I am taking is running
gatsby build
. After downgrading back to 2.0.83, the issue disappears.Expected result
The build should complete successfully
Actual result
The build quits with the following error:
Environment
I saw #10038 which sounded familiar, but my Webpack config is uninteresting:
And commenting that block out does not fix the error.
If I replace
gatsby-plugin-offline
withgatsby-plugin-remove-serviceworker
, the problem remains, but with a different async import.FWIW, I do not notice a difference in the contents of
async-require.js
in the 2.0.83 or 2.0.84 builds and upgradinggatsby-plugin-offline
made no difference as well.The text was updated successfully, but these errors were encountered: