-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Storybook 3.2 is failing to build static export #1570
Comments
This could be because UglifyJS doesn't support any ES6 yet. |
Do you recommend any plugin I should use for that? |
I have the same problem, trying to find some workaround |
Here is my workaround, it's not a good idea but it works for now: Just get rid of UglifyJs on prod. Create a new
|
I have the same issue:
|
I can confirm the hack of @hakimelek solves the problem. Here's how to handle it if you normally use extension mode you have to apply the merge manually: const merge = require('webpack-merge')
const sharedWebpackConfig = require('./../config/webpack/shared');
module.exports = (storybookBaseConfig, configType) => {
if (configType === 'PRODUCTION') {
// Removing uglification until we figure out a fix for that.
storybookBaseConfig.plugins.pop();
}
const extension = {
resolve: {
modules: [
'node_modules',
'../frontend'
]
},
plugins: sharedWebpackConfig.plugins,
module: {
rules: sharedWebpackConfig.module.rules
},
};
return merge(storybookBaseConfig,extension);
}; |
It relies on the fact that uglify plugin is first, I use |
@ndelangen why does storybook's static build even require minification, would it not be beneficial to leave it unminified because the end users might want to check the output in react developer tools to see the components if this tool is meant for development? Also, if I use another minifier plugin in my Also, given that you do not support a custom babel config, why should I use a babel config for the entire app that transpiles to ES5 when most browsers have good support for ES6. |
Only in full control mode (the one used in snippets above) |
Well, it's only half true. It's supported, but only in form of local |
I was experiencing this as well. My issue seems to stem from a dependency of a dependency that looks to be unwilling to build a compiled source that is suitable for webpack/babel. sindresorhus/stringify-object#35 It looks to be compiling within their node_module to preserve arrow functions that uglify implodes on. Any thoughts from anyone on how to handle this? |
Well, this is exactly the "issue with third-party addon" I was talking about =) My solution was to disable UglifyJS, but if you want to target pre-ES6 browser, looks like you have to transpile that module (and its dependency |
@ndelangen - shouldn't this make sure it's transpiled to ES5? |
It does, but only for the files included into babel-loader rule ( |
FYI, our
|
I've found that I experience a similar issue, though not quite the same. Not sure if it should be a separate issue, if so, please say so. Anyway, I'm using a custom {
"presets": [
"es2015",
"react",
"env"
],
"plugins": ["add-react-displayname"],
"env": {
"development": {
"sourceMaps": "inline"
},
"production": {
"ignore": [
"*.stories.js",
"*.test.js"
]
},
"test": {
"plugins" : ["istanbul"]
}
}
} When I run Module parse failed: /my-storybook-app/node_modules/@storybook/react/node_modules/babel-loader/lib/index.js??ref--0!/my-storybook-app/src/Welcome.stories.js Unexpected token (10:4) You may need an appropriate loader to handle this file type. | storiesOf('Readme', module) | .add('to Storybook', () => ( | <Welcome showApp={linkTo('Button')} /> | )); |
Error: Module parse failed: /my-storybook-app/node_modules/@storybook/react/node_modules/babel-loader/lib/index.js??ref--0!/my-storybook-app/src/Welcome.stories.js Unexpected token (10:4)
You may need an appropriate loader to handle this file type.
| storiesOf('Readme', module)
| .add('to Storybook', () => (
| <Welcome showApp={linkTo('Button')} />
| ));
|
at Object.<anonymous> (http://localhost:8000/static/preview.e526a42327b2c689d21b.bundle.js:1:765870)
at __webpack_require__ (http://localhost:8000/static/preview.e526a42327b2c689d21b.bundle.js:1:223)
at webpackContext (http://localhost:8000/static/preview.e526a42327b2c689d21b.bundle.js:1:877040)
at http://localhost:8000/static/preview.e526a42327b2c689d21b.bundle.js:1:719379
at Array.forEach (<anonymous>)
at loadStories (http://localhost:8000/static/preview.e526a42327b2c689d21b.bundle.js:1:719345)
at ConfigApi.value (http://localhost:8000/static/preview.e526a42327b2c689d21b.bundle.js:1:755013)
at render (http://localhost:8000/static/preview.e526a42327b2c689d21b.bundle.js:1:755498)
at ConfigApi.value (http://localhost:8000/static/preview.e526a42327b2c689d21b.bundle.js:1:755762)
at Object.<anonymous> (http://localhost:8000/static/preview.e526a42327b2c689d21b.bundle.js:1:719646) Once I remove Any suggestions as to what might cause the problem in my |
build-storybook doesn't currently use the custom issue tracked here: #1731 |
@danielduan I've recently upgraded a bunch of webpack configs to use the uglifyjs-webpack-plugin which uses uglifyjs v1, rather than 0.4* that is under webpack.optimize.UglifyJsPlugin. I did the same in the extension mode of the storybook webpack config by removing the existing plugin and adding uglifyjs-webpack-plugin instead. The issue appears fixed, so maybe upgrading the webpack config to use this plugin by default rather than the bundled webpack plugin might help? (I haven't had any issues upgrading to the latest uglifyjs, however I didn't do a full analysis of the changes between the 2 versions, and the webpack team hasn't upgraded to this. This could be because the config format for the v1 version has changed) |
@hermanvos Thank you so much for giving that a test, It's been on my agenda for sure, but I've been a bit overloaded with many different things that I just haven't been able to open a branch and check it out. Again thanks! We update a ton of packages semi automatically, but maybe this package is special in some way. Any help you can provide with a PR and testing is very welcome! @Hypnosphi does most of the dependendencies-updates these days with a tool https://www.dependencies.io/. I'm giving them a shout-out because their service is awesome! |
We don't use it directly, only via webpack's builtin plugin |
Will try and come up with a pull request over the next couple of days... |
If anyone else needs a quick workaround for this issue that still minifies the static build here's my workaround. It swaps the Webpack plugin for UglifyJs with the plugin for babel minify.
const MinifyPlugin = require("babel-minify-webpack-plugin");
module.exports = (storybookBaseConfig, configType) => ({
...storybookBaseConfig,
plugins: storybookBaseConfig.plugins.reduce((pluginsList, plugin) => ([
...pluginsList,
configType === 'PRODUCTION' && plugin.constructor.name === 'UglifyJsPlugin'
? new MinifyPlugin({mangle: false})
: plugin
]), [])
}); |
@hermanvos Need any help opening a PR? If there's anything I can do to help, let me know! |
@ndelangen I have a change but haven't been able to test it yet... will try and get on to it this week. |
@jkingworking 's solution didn't work for me for some reason - my even more table-flippy version: module.exports = (storybookBaseConfig, configType) => ({
...storybookBaseConfig,
plugins: storybookBaseConfig.plugins.filter((plugin) =>
plugin.constructor.name !== 'UglifyJsPlugin'
)}); |
@AshCoolman Theoretically this is not needed anymore with latest versions of storybook. |
* RSP-20:React 16 upgrade * RSP-20:React 16 upgrade *updating tests(failed) * RSP-20:React 16 upgrade *updating tests(failed) * did some updates to libraries * updated libraries, etc * package upgrades done for r16. starting test fixing * fixed autocomplete, start calendar" * fixed toasts tests..mainly had to call update()0 * fix tablist - mainly disabledlifecyclemethods so we don't call componentDidMount * testing fixes finished, 584 tests passing * removed logs * responded to code review by NR * added package-lock.json to gitignore * reverted changes to npmrc..wasn't supposed to be pushed * remove changes to package.json * Test cleanup * Fix storybook styling strangeness * Fix CalendarCell tests * Upgrade react-overlays version Fixes ModalContainer/Portal things for react 16 * Convert Underlay to a class component Functional components cannot have refs in React 16 * Test against multiple versions of react * Disable uglifyjs on storybook builds storybookjs/storybook#1570 * Add default enzyme adapter * Fix for ref race condition error (#86)
.babelrc
{ "presets": ["es2015", "stage-0", "react"] }
Running build-storybook throws this error. It looks like we should use
uglifyjs-webpack-plugin
according to https://stackoverflow.com/questions/42375468/uglify-syntaxerror-unexpected-token-puncThe text was updated successfully, but these errors were encountered: