-
Notifications
You must be signed in to change notification settings - Fork 1k
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Production build does not handle node_modules containing es6 code #3865
Comments
Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible. |
For easy repro my build was being broken by query-string which started shipping ES6 in v6 |
@TheTedAdams, Any tips on how to get around this issue when using query-string? I'm working on a SPFx 1.8 project. My workaround is to install version 5.1.1. You still get an error "The build failed because a task wrote output to stderr." but at least the package you get in the end seems to work. If you have a better workaround, please let me know. |
@semopz yes for now I did the same thing, I assume if you wanted to handle it yourself you could edit your 'use strict';
const gulp = require('gulp');
const build = require('@microsoft/sp-build-web');
build.addSuppression(`Warning - [sass] The local CSS class 'ms-Grid' is not camelCase and will not be type-safe.`);
build.configureWebpack.mergeConfig({
additionalConfiguration: (generatedConfiguration) => {
generatedConfiguration.externals.splice(generatedConfiguration.externals.indexOf('react'), 1);
generatedConfiguration.externals.splice(generatedConfiguration.externals.indexOf('react-dom'), 1);
return generatedConfiguration;
}
});
build.initialize(gulp); Obviously this was to remove external react references so that I could ship w/ react@16... but it highlights the way you can modify the webpack configuration to suit your needs, and you could probably use this to add a babel loader. I just haven't tried yet. |
Cool thanks. I'm not sure if I'll be trying the babel approach as query-string is the only thing that's impacting my project. I see that a 'community' label has been tagged on this issue. I have no idea what the labels mean in this repo. Does it mean that this issue is not considered a bug or it won't be fixed? |
Not sure this is still an issue... I can't repro with 1.9.1... |
The move to WebPack v4 means that things seem to now be uglified using the Terser plugin, which as I mentioned does not die on ES6 code. The current SPFx build does NOT do anything to make node_modules safe (no babel loader or anything like that) but it no longer breaks. If you are fine shipping code to SharePoint that doesn't have to run in IE... you'll be fine and you work at a cool company. Closing. |
I also just wanted to add here in case anybody finds this via search, I was able to add a babel-loader for node_modules if you want to use es6 node_modules that ship in ES6, like query-string v6+ build.configureWebpack.mergeConfig({
additionalConfiguration: generatedConfiguration => {
// Add a babel loader to transform node_modules to be IE safe
process.env.BABEL_ENV = 'production';
generatedConfiguration.module.rules.push({
test: /\.(js)$/,
include: /node_modules/,
exclude: /@babel(?:\/|\\{1,2})runtime|core-js|react|react-dom/,
loader: require.resolve('babel-loader'),
options: {
babelrc: false,
configFile: false,
compact: false,
presets: [
[
'@babel/preset-env',
{
useBuiltIns: false,
},
],
],
cacheDirectory: true,
cacheCompression: true,
sourceMaps: false,
},
});
return generatedConfiguration;
},
}); |
Issues that have been closed & had no follow-up activity for at least 7 days are automatically locked. Please refer to our wiki for more details, including how to remediate this action if you feel this was done prematurely or in error: Issue List: Our approach to locked issues |
Category
Expected or Desired Behavior
Production build (--ship flag) is not broken by node_modules containing ES6 code.
Observed Behavior
Using SPFx 1.8,
gulp serve
works, butgulp build --ship
does not, returning the following error:Based on the absurd line numbers and the
.js
extension this seems to be happening after typescript and after the bundle has been concatenated together... Given that my tsconfig targets ES5 my belief is a node_module shipping es6 code (which is starting to happen more frequently as library maintainers abandon IE support) is being put in the bundle, which is then being run through uglifyjs-webpack-plugin. uglifyjs-webpack-plugin, being tied to uglify-js, does not support es6 syntax.Resolution suggestions
I see two possible resolutions.
'production'
due to uglify-js deciding not to support ES6 syntax, so when we migrate to Webpack 4 we'll most likely be using terser anyway.Steps to Reproduce
Use a node_module that has begun shipping their distributed .js in ES6.
Attempt to
gulp build --ship
Observe
UglifyJs
errors.This is likely the same bug as #1422
The text was updated successfully, but these errors were encountered: