我在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.
],
},
};
答案 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及以下节点已经长时间不在画面中了。