Skip to content
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

Static builds fail while dev-server works fine, getCode() is undefined error #9261

Closed
weyert opened this issue Dec 30, 2019 · 5 comments
Closed

Comments

@weyert
Copy link
Contributor

weyert commented Dec 30, 2019

Describe the bug
I am having an issue with Storybook failing to make a successful static build using build-storybook-command while start-storybook-command is working as expected.

I noticed when change the file @storybook/core/dist/server/common/babel.js in such manner that the createProdPresets-method doesn't return the babel-preset-minify the build is succesful. For example, like this:

function createProdPresets() {
  return [
    // [
    //   require.resolve('babel-preset-minify'), {
    //     builtIns: false,
    //     mangle: false
    //   }
    // ]
  ];
}

The following errors is given by Storybook when building:

➜ yarn run storybook:build          
yarn run v1.21.1
$ build-storybook -o other/public/storybook
info @storybook/react v5.3.0-rc.4
info 
info clean outputDir..
info => Copying prebuild dll's..
info => Building manager..
info => Loading manager config..
info => Loading presets
info => Loading custom manager config.
info => Compiling manager..
ERR! => Failed to build the manager
ERR! ./.storybook/addons.js
ERR! Module build failed (from ./node_modules/babel-loader/lib/index.js):
ERR! TypeError: /Users/weyertdeboer/experiment/.storybook/addons.js: Cannot read property 'getCode' of undefined
ERR!     at NodePath.getSource (/Users/weyertdeboer/experiment/node_modules/@babel/traverse/lib/path/introspection.js:150:27)
ERR!     at PluginPass.Program (/Users/weyertdeboer/experiment/node_modules/babel-plugin-minify-simplify/lib/index.js:490:41)
ERR!     at newFn (/Users/weyertdeboer/experiment/node_modules/@babel/traverse/lib/visitors.js:179:21)
ERR!     at NodePath._call (/Users/weyertdeboer/experiment/node_modules/@babel/traverse/lib/path/context.js:55:20)
ERR!     at NodePath.call (/Users/weyertdeboer/experiment/node_modules/@babel/traverse/lib/path/context.js:42:17)
ERR!     at NodePath.visit (/Users/weyertdeboer/experiment/node_modules/@babel/traverse/lib/path/context.js:90:31)
ERR!     at TraversalContext.visitQueue (/Users/weyertdeboer/experiment/node_modules/@babel/traverse/lib/context.js:112:16)
ERR!     at TraversalContext.visitSingle (/Users/weyertdeboer/experiment/node_modules/@babel/traverse/lib/context.js:84:19)
ERR!     at TraversalContext.visit (/Users/weyertdeboer/experiment/node_modules/@babel/traverse/lib/context.js:140:19)
ERR!     at Function.traverse.node (/Users/weyertdeboer/experiment/node_modules/@babel/traverse/lib/index.js:84:17)
ERR!     at traverse (/Users/weyertdeboer/experiment/node_modules/@babel/traverse/lib/index.js:66:12)
ERR!     at transformFile (/Users/weyertdeboer/experiment/node_modules/@babel/core/lib/transformation/index.js:119:29)
ERR!     at runSync (/Users/weyertdeboer/experiment/node_modules/@babel/core/lib/transformation/index.js:48:5)
ERR!     at runAsync (/Users/weyertdeboer/experiment/node_modules/@babel/core/lib/transformation/index.js:35:14)
ERR!     at /Users/weyertdeboer/experiment/node_modules/@babel/core/lib/transform.js:34:34
ERR!     at processTicksAndRejections (internal/process/task_queues.js:75:11)
ERR!  @ multi ./node_modules/@storybook/core/dist/server/common/polyfills.js ./.storybook/addons.js ./node_modules/@storybook/core/dist/client/manager/index.js main[1]
(node:45258) UnhandledPromiseRejectionWarning: [object Object]
(node:45258) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:45258) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

To Reproduce
Still working on a reproducible case

Expected behavior
I would expect that running build-storybook-command would succeed without errors just like running the start-storybook-command

Code snippets
If applicable, add code samples to help explain your problem.

System:

Environment Info:

  System:
    OS: macOS 10.15.2
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
  Binaries:
    Node: 12.14.0 - ~/.nodenv/versions/12.14.0/bin/node
    Yarn: 1.21.1 - /usr/local/bin/yarn
    npm: 6.13.4 - ~/.nodenv/versions/12.14.0/bin/npm
  Browsers:
    Chrome: 79.0.3945.88
    Firefox: 70.0.1
    Safari: 13.0.4
  npmPackages:
    @storybook/addon-a11y: next => 5.3.0-rc.4 
    @storybook/addon-actions: next => 5.3.0-rc.4 
    @storybook/addon-console: ^1.2.1 => 1.2.1 
    @storybook/addon-contexts: next => 5.3.0-rc.4 
    @storybook/addon-info: next => 5.3.0-rc.4 
    @storybook/addon-jest: next => 5.3.0-rc.4 
    @storybook/addon-notes: next => 5.3.0-rc.4 
    @storybook/addon-viewport: next => 5.3.0-rc.4 
    @storybook/react: next => 5.3.0-rc.4 

Additional context
I am using a customised version of kcd-scripts which adds TypeScript support for babel and webpack.

@weyert
Copy link
Contributor Author

weyert commented Dec 30, 2019

Looks like there isn't a way to disable this preset from being added?
If I adapt the above babel-preset-minify to the snippet listed below it seems to compile so it looks like simplify-option is causing the breakage:

function createProdPresets() {
  return [
    [
      require.resolve('babel-preset-minify'), {
        "builtIns": false,
        "mangle": false,
        "simplify": false,
      }
    ]
  ];
}

@shilman
Copy link
Member

shilman commented Dec 31, 2019

@weyert Any chance you can submit a PR for this?

@weyert
Copy link
Contributor Author

weyert commented Dec 31, 2019

@shamin I have made a PR for it :) And Happy New Year :)

@shilman
Copy link
Member

shilman commented Jan 2, 2020

Great Caesar's ghost!! I just released https://github.com/storybookjs/storybook/releases/tag/v5.3.0-rc.7 containing PR #9280 that references this issue. Upgrade today to try it out!

You can find this prerelease on the @next NPM tag.

Closing this issue. Please re-open if you think there's still more to do.

@shilman shilman closed this as completed Jan 2, 2020
@apefrown
Copy link

apefrown commented Jan 2, 2020

Unfortunately the addition of simplify: false in the babel-preset-minify options in v5.3.0-rc.7 doesn't resolve a similar issue for me.

Removing builtIns: false does allow the static build of my Storybook though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants