-
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
"gatsby build" breaks when dependencies use es6 code (which Uglify doesn't support) #3780
Comments
i am also seeing this. except for me it's running out of memory when trying to build the JS bundles, however pinning to the version you mentioned |
In my case it's caused by However, this means that all dependencies should also be compiled by Babel to ES5, because they might be written in ES6, so even if Gatsby started using UglifyJS2, which does support ES6 syntax, it would break in older browsers that don't support ES6. |
Experiencing this too - big dealbreaker as far as I'm concerned. |
Gatsby has never compiled code in CRA will be compiling code in node_modules w/ babel starting in their v2 which we can consider as well. facebook/create-react-app#3776 @szimek that PR only affects the Typescript plugin. We haven't changed anything related to Babel in a long time. @alexjsdev are you using the typescript plugin? |
I would have thought so too @KyleAMathews, but I can verify that it builds correctly on Gatsby |
@ryami333 fair enough — could you post a link to a site reproducing this problem? All the example sites and gatsbyjs.org are still building correctly AFAIK so something reproducing this would be great. |
I'll see what I can do, but it might take a little while. In the meantime, I verified that the break is between builds |
@KyleAMathews no we are not using typescript, just the out of the box gatsby starter setup, with what was the latest Gatsby at the time which was 1.9.176 (i believe). We would get an UglifyJS running out of memory error when Gatsby would try to compile our JS bundles, but then i found this thread and based on @szimek suggestion tried pinning the version to On a side note, I tried updating to the latest a few days ago (1.9.177) and although gatsby would successfully run Thanks for all your help! And btw Gatsby is truly genius! |
@KyleAMathews just saw that there's a newer version
|
@alexjsdev is your issue actually related to the OP? Have you verified that your dependency is indeed ES6? |
@KyleAMathews I've created a demo repo here, based on
|
You're right. Turns out that Gatsby 1.9.166 and earlier versions silently skip the minification of a file, if it uses ES6 syntax after bundling, e.g. when I use According to facebook/create-react-app#1125 (comment) it's not safe to run Babel 6 on Here's PR that adds compiling dependencies with |
I can also confirm that this is happening. In my particular case, it is caused by a Downgrading to |
@szimek yeah, planning on copying CRA's implementation for Gatsby v2. |
Folks running into this — what do think we should do? Remove the error? Add easy way to compile problematic packages? Just removing the error doesn't really solve much as now you're shipping unminified es6 code which is a) slower cause it's unminified and b) will break older browsers that don't support whatever es6 features are used in the code. |
Why isn't using an es6-compatible version of Uglify an option?
Get Outlook for Android<https://aka.ms/ghei36>
…________________________________
From: Kyle Mathews <notifications@github.com>
Sent: Tuesday, February 6, 2018 4:14:17 PM
To: gatsbyjs/gatsby
Cc: Mitch Ryan; Mention
Subject: Re: [gatsbyjs/gatsby] "gatsby build" breaks when dependencies use es6 code (which Uglify doesn't support) (#3780)
Folks running into this — what do think we should do? Remove the error? Add easy way to compile problematic packages? Just removing the error doesn't really solve much as now you're shipping unminified es6 code which is a) slower cause it's unminified and b) will break older browsers that don't support whatever es6 features are used in the code.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#3780 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AL5z_PbtaWjW47jYiSPvh-WYBO8U7MFfks5tR8OJgaJpZM4Ry0kI>.
|
That could be a possibility too — I haven't researched it. Actually, just researched it :-) and it looks like it might require webpack v3 — so we should do this upgrade along with the remainder of the Gatsby v2 work facebook/create-react-app#3618 |
There are 2 issues. When Gatsby switches to |
@KyleAMathews Could be possible setup an Uglify ES6-compatible on Just as workaround to avoid not update Looks like, if I don't update
EDIT: In my case looks a very isolate problem related with a subdependency from
|
@Kikobeats it's best to fix your dependency by compiling it to es5. Not updating Gatsby just means your build succeeds not that the underlying problem, that your code isn't minifying and that it's not runnable on older browsers, is fixed. |
Working on fixes for this in Gatsby v2. We'll be compiling all code in node_modules + upgrading to the latest version of uglify. |
@m-allanson thank you so much for your help! |
Did anyone found a solution for this? I'm having the same problem. Here are my gatsby.config
and my dependencies
|
Hi all. I'm having similar issue with 'query-string' package. I'm fine with not having my site working on older browsers... what are people doing to get to solution where it just skips over the ES6 packages? I saw @KyleAMathews is pushing out v2 (woohoo! thanks dude!) but that's causing other errors for me so wanted to find a solution while v2 settles in :) |
@natesjacobs I solved my problem my removing async/await from my app. Apparently, the v1 does not support it yet. Check if you have any and change it to the good old callbacks ;-) |
@natesjacobs I ran into the same issue and had to use |
I had same issue upgrading to to a module dependency that uses exports.modifyWebpackConfig = ({ config, stage }) => {
// https://www.gatsbyjs.org/docs/add-custom-webpack-config/#modifying-the-babel-loader
const program = {
directory: __dirname,
browserslist: ["> 1%", "last 2 versions", "IE >= 9"]
};
return generateBabelConfig(program, stage).then(babelConfig => {
config.removeLoader("js").loader("js", {
test: /\.jsx?$/,
exclude: modulePath => {
return (
/node_modules/.test(modulePath) &&
// whitelist specific es6 modules
!/node_modules\/(react-docgen|ast-types|recast)/.test(modulePath)
);
},
loader: "babel",
query: babelConfig
});
});
} |
@KyleAMathews Won't that significantly increase the build time? Sticking with |
Yes — we've actually decided to wait and see a bit more on the issue of compiling node_modules. Both because of the slowdowns and because there's a lot of active discussions around how it should work. |
If anyone else comes across this issue when they are using Gatsby V2, the above examples will not work due to Gatsby API changes, but the below example did (at least for me).
In the above example, the |
Could this functionality be outsourced to a plugin? Something where you could just provide a list of node_module packages that need to be transpiled. In the implementation, it just does the |
Yeah! This should totally be a plugin. Anyone up for creating it? |
@KyleAMathews I will have a crack at a plugin for Gatsby V2 using something like my example above (#3780 (comment)) Perhaps I should call it |
@robwalkerco awesome! How about maybe |
@KyleAMathews Ah, thats a good name.
Could try to get the name changed though. If anyone else finds this issue, then the plugin will help you to customise the webpack config to compile es6 modules in node_modules. Open to PR's to improve the readme etc |
After sleeping on it, I've decided that @KyleAMathews plugin name makes much more sense, so have moved the plugin to https://www.npmjs.com/package/gatsby-plugin-compile-es6-packages I hope you find it useful 😄 Also closing this issue now, as using this plugin and configuring it with the npm packages that have es6 code in them will allow them to be compiled by Babel. |
I'm working in a 'monorepo' and trying to figure out if I need @robwalkerco's plugin. The app is structured like:
…where Should I be adding |
Unclear whether this is a steadfast solution or a patch for the issue of having ES6+ code in a npm dependency, but for now it allows the docs site to be run locally. Ref: gatsbyjs/gatsby#3780 Ref: mdx-js#542
Unclear whether this is a steadfast solution or a patch for the issue of having ES6+ code in a npm dependency, but for now it allows the docs site to be run locally. Ref: gatsbyjs/gatsby#3780 Ref: mdx-js#542
Unclear whether this is a steadfast solution or a patch for the issue of having ES6+ code in a npm dependency, but for now it allows the docs site to be run locally. Ref: gatsbyjs/gatsby#3780 Ref: mdx-js#542
Unclear whether this is a steadfast solution or a patch for the issue of having ES6+ code in a npm dependency, but for now it allows the docs site to be run locally. Ref: gatsbyjs/gatsby#3780 Ref: #542
Description
After upgrading Gatsby to 1.9.167, I'm getting the following error when I try to run
gatsby build
:The line mentioned in the error contains keyword
let
. Looks like (at least) dependencies are no longer compiled to ES5 and UglifyJS version used by Gatsby doesn't understand ES6+, so it throws an error.The same app works fine with 1.9.166. It's most likely caused by some changes introduced in #3369, other changes introduced in this version don't look suspicious.
To replicate this issue create a new Gatsby project, run
yarn add camelcase
, import and callcamelcase
in any component and rungatsby build
.The text was updated successfully, but these errors were encountered: