storybook-readme icon indicating copy to clipboard operation
storybook-readme copied to clipboard

Broken build with webpack v4.29.x

Open kakadiadarpan opened this issue 6 years ago • 24 comments

Hello, I really love the work you have done on this package and it has been really helpful.

I'm not sure if I missed anything in the migration but I have a broken build at the moment. Would be great if someone could check the details below and help.

I'm using [email protected] with storybook v5.

// addons.js
import 'storybook-readme/register';
// config.js
import { addDecorator } from '@storybook/react';
import { addReadme } from 'storybook-readme';
addDecorator(addReadme);
// component.stories.js
import { storiesOf } from '@storybook/react';
import React from 'react';
import Readme1 from './readme-1`;
import Readme2 from './readme-2`;
import MyComponent from './component';

storiesOf('Component 1', module)
    .addParameters({
        readme: {
            content: [Readme1, Readme2]
        }
    })
    .add('basic', () => <MyComponent id="id" />);

WARN FATAL broken build!, will close the process, WARN Fix the error below and restart storybook.

ModuleParseError: Module parse failed: 'import' and 'export' may only appear at the top level (21:2) You may need an appropriate loader to handle this file type. | } |

import("./codeThemes/".concat(codeTheme, ".css.js")).then(function (t) { | insert({ | styles: t.default at handleParseError (/node_modules/webpack/lib/NormalModule.js:447:19) at doBuild.err (/node_modules/webpack/lib/NormalModule.js:481:5) at runLoaders (/node_modules/webpack/lib/NormalModule.js:342:12) at /node_modules/loader-runner/lib/LoaderRunner.js:373:3 at iterateNormalLoaders (/node_modules/loader-runner/lib/LoaderRunner.js:214:10) at Array. (/node_modules/loader-runner/lib/LoaderRunner.js:205:4) at Storage.finished (/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:43:16) at provider (/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:79:9) at /node_modules/graceful-fs/graceful-fs.js:90:16 at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:511:3)

kakadiadarpan avatar Mar 19 '19 10:03 kakadiadarpan

There is dynamic import is using in codeThemeCSS.js but it should not cause an error.

  • Do you have additional webpack configuration?
  • try to remove all node_modules and install it again

tuchk4 avatar Mar 19 '19 10:03 tuchk4

I do have an additional webpack configuration, but it should not be crashing it:

new webpack.NormalModuleReplacementPlugin(
    /my-constants\/index\.js/,
    __dirname + '/my-constants/override-index.js'
)

I'll try to remove my node_modules and see if that works. Thanks for the quick reply! 😄

kakadiadarpan avatar Mar 19 '19 10:03 kakadiadarpan

Seems it is related to https://github.com/webpack/webpack/issues/8656

In this case build also should be broken at my env. Will check it twice right now

tuchk4 avatar Mar 19 '19 11:03 tuchk4

Make some tests with the latest version of storybook-readme and @storybook/react and still can not reproduce

tuchk4 avatar Mar 19 '19 11:03 tuchk4

@kakadiadarpan I also can't reproduce it on my windows and ubuntu with simple CRA

lonyele avatar Mar 19 '19 11:03 lonyele

  • Removed node_modules/ and installed packages again, that didn't help.
  • Tried removing custom webpack config, that also didn't help.

This is the list of all the storybook packages I'm using:

{
    "@storybook/addon-a11y": "5.0.0",
    "@storybook/addon-backgrounds": "5.0.0",
    "@storybook/addon-info": "5.0.0",
    "@storybook/addon-knobs": "5.0.0",
    "@storybook/addon-viewport": "5.0.0",
    "@storybook/addons": "5.0.0",
    "@storybook/core-events": "5.0.0",
    "@storybook/react": "5.0.0",
    "@storybook/theming": "5.0.0",
    "storybook-readme": "5.0.0",
}

Not sure if I'm doing anything wrong. 😕

kakadiadarpan avatar Mar 19 '19 12:03 kakadiadarpan

Try this versions

{
    "@storybook/addon-a11y": "^5.0.3",
    "@storybook/addon-backgrounds": "^5.0.3",
    "@storybook/addon-info": "^5.0.3",
    "@storybook/addon-knobs": "^5.0.3",
    "@storybook/addon-viewport": "^5.0.3",
    "@storybook/addons": "^5.0.3",
    "@storybook/core-events": "^5.0.3",
    "@storybook/react": "^5.0.3",
    "@storybook/theming": "^5.0.3",
    "storybook-readme": "^5.0.0",
}

tuchk4 avatar Mar 19 '19 17:03 tuchk4

@kakadiadarpan Did you that versions? Any updates?

tuchk4 avatar Mar 20 '19 11:03 tuchk4

I receive the same error. Downgrading to webpack 4.28.2 resolved the issue for me.

neardark avatar Mar 20 '19 17:03 neardark

I'm also receiving an error:

ERROR in ./node_modules/storybook-readme/styles/codeThemeCss.js 21:2
Module parse failed: 'import' and 'export' may only appear at the top level (21:2)
You may need an appropriate loader to handle this file type.
|   }
|
>   import("./codeThemes/".concat(codeTheme, ".css.js")).then(function (t) {
|     insert({
|       styles: t.default
 @ ./node_modules/storybook-readme/components/ReadmeContent/index.js 36:43-79
 @ ./node_modules/storybook-readme/index.js
 @ ./stories/index.js
 @ ./.storybook/config.js
 @ multi ./node_modules/@storybook/core/dist/server/common/polyfills.js ./node_modules/@storybook/core/dist/server/preview/globals.js ./.storybook/config.js (webpack)-hot-middleware/client.js?reload=true

My start script is "start": "start-storybook -p 8080 -c .storybook"

I'm using the following modules:

    "@storybook/addon-actions": "^5.0.3",
    "@storybook/addon-options": "^5.0.3",
    "@storybook/react": "^5.0.3",
    "storybook-readme": "^5.0.1",
    "webpack": "^4.29.6",
    "webpack-cli": "^3.3.0"

If you need more information let me know.


EDIT: Downgrading also worked for me. Hopefully webpack releases a fix!

JosephScript avatar Mar 20 '19 18:03 JosephScript

Seems this is webpack related issue. https://github.com/webpack/webpack/issues/8656

Will try to find workaround until webpack issue is not resolved :(

tuchk4 avatar Mar 20 '19 23:03 tuchk4

Thank you for the update @tuchk4! I'll check if I can downgrade my webpack version for now.

kakadiadarpan avatar Mar 21 '19 08:03 kakadiadarpan

@tuchk4 Seems it's an npm issue as per Tobias's comment. Should work fine with yarn as confirmed in this comment

I'll use yarn and check if it fixes this issue for me

kakadiadarpan avatar Mar 21 '19 09:03 kakadiadarpan

FYI: If you'd like to stick with npm and downgrading webpack is an option for you, [email protected] works fine with dynamic imports.

kristofdombi avatar Mar 21 '19 19:03 kristofdombi

@kristof0425 Thanks, but I don't want to downgrade a dependency when I can just switch to yarn and that fixes the problem without downgrading a package. (And I personally like yarn more than npm anyways 😅)

Also, I don't know if this issue would be fixed anytime soon as per this discussion

kakadiadarpan avatar Mar 22 '19 12:03 kakadiadarpan

I've downgrade the webpack to v4.28.4 and i get the same error. For storybook i have those packages:

{
  "@storybook/theming": "^5.0.5",
  "@storybook/addon-backgrounds": "^5.0.5",
  "@storybook/addon-actions": "^5.0.5",
  "@storybook/addon-knobs": "^5.0.5",
  "@storybook/addon-viewport": "^5.0.5",
  "@storybook/addons": "^5.0.5",
  "@storybook/vue": "^5.0.5,
   storybook-readme": "^5.0.1"
}

I've comment these lines in storybook-readme/codeThemeCss.js package (just for testing) and it works

  import("./codeThemes/".concat(codeTheme, ".css.js")).then(function (t) {
    insert({
      styles: t.default
    });
  });

I can't find a way to solved that

didiermargarido avatar Mar 25 '19 14:03 didiermargarido

Moving to yarn from npm fixed the issue for me

/cc @tuchk4

kakadiadarpan avatar Mar 25 '19 14:03 kakadiadarpan

Moving to yarn from npm fixed the issue for me

/cc @tuchk4

Thanks @tuchk4 but unfortunately i have to work with npm. There isn't another way to fix that?

didiermargarido avatar Mar 25 '19 14:03 didiermargarido

I'm not sure if there's another way. Downgrading the webpack version worked for others though

kakadiadarpan avatar Mar 25 '19 14:03 kakadiadarpan

I solved my problem adding those extra packages acorn (javascript parsers):

{
   "acorn": "^6.1.1",
   "acorn-dynamic-import": "^4.0.0"
}

It also work with [email protected] and those storybook versions:

{
   "@storybook/theming": "^5.0.5",
   "@storybook/addon-actions": "^5.0.5",
   "@storybook/addon-knobs": "^5.0.5",
   "@storybook/addon-viewport": "^5.0.5",
   "@storybook/addons": "^5.0.5",
   "@storybook/vue": "^5.0.5",
   "storybook-readme": "^5.0.1"
}

Others informations: Node v10.15.3 NPM v6.9.0

Thank you anyway @kakadiadarpan

didiermargarido avatar Mar 26 '19 01:03 didiermargarido

Hello @didiermargarido, for me even adding both packages also end-up with no luck? Anything extra I need to do apart-from downgrading the webpack, I am on [email protected] at the moment, along with @storybook/* ^5.0.5

hitendramalviya avatar Mar 26 '19 15:03 hitendramalviya

Hi @hitendramalviya . Im also working with [email protected] and [email protected] and after adding the acorn packages the build worked without errors. Have you tried to downgrade your webpack package to 4.28.4?

didiermargarido avatar Mar 26 '19 18:03 didiermargarido

I have to gone through a list of related issues on webpack & found my answer as npm bug, but one of listed workaround (deleting package-lock.json file & installing packages again) did the trick for me.

https://github.com/webpack/webpack/issues/8656#issuecomment-456713191

hitendramalviya avatar Mar 28 '19 18:03 hitendramalviya

published 5.0.3 that should fix this issue. Dynamic import was used for code theme lazy loading. Now all code themes are bundled: https://github.com/tuchk4/storybook-readme/blob/f699e99b2ce808268390aa687882bbdcf3e4151b/packages/storybook-readme/src/styles/codeThemeCss.js#L5-L21. So this affects on bundle size.

When webpack fix https://github.com/webpack/webpack/issues/8656 I will rollback this.

tuchk4 avatar May 02 '19 21:05 tuchk4