故事书不适用于带有webpack + babel的node7?

时间:2019-04-12 22:52:36

标签: reactjs npm webpack storybook

我在React项目中使用node7.2.1和npm 5.6.0。该项目由webpack2管理。我试图在此项目中添加storybook,但编译失败。我在运行storybook时遇到的错误是:

TheFrontEnd/node_modules/@storybook/core/dist/server/build-static.js:31
async function compileManager(managerConfig, managerStartTime) {
      ^^^^^^^^
SyntaxError: Unexpected token function
    at Object.exports.runInThisContext (vm.js:78:16)
    at Module._compile (module.js:543:28)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)

我知道与es6语法有关。但是我在.babelrc目录下创建了一个.storybook/文件,但这似乎无济于事。我添加的babel文件是:

{
  "presets": [
    "es2015",
    "stage-2",
    "react"
  ],
  "plugins": [
    "transform-decorators-legacy",
    "transform-class-properties",
    "transform-async-to-generator",
    "transform-object-rest-spread",
    "add-module-exports",
    "react-hot-loader/babel"
  ]
}

故事书的webpack文件为:(.storybook / webpack.config.js)

module.exports = {
  plugins: [
    // your custom plugins
  ],
  module: {
    rules: [
      // add your custom rules.
    ],
  },
};

1 个答案:

答案 0 :(得分:0)

很不幸,Storybook需要Node 8.6+:https://github.com/storybooks/storybook/blob/next/package.json#L190-L193

https://github.com/storybookjs/storybook/issues/6510

自2018年初以来,Storybook至少需要3.0版以上的Node: https://github.com/storybookjs/storybook/blob/89af8fe76f21bd89d7c86c6134bce030873122bc/package.json

因此,节点7,节点6及以下节点已经长时间不在画面中了。