【发布时间】:2016-07-08 18:50:21
【问题描述】:
我使用got 作为 npm 包并将其导入我的组件之一。当我在 Safari 中通过 Webpack only 运行所有内容时,它会说:
SyntaxError: Unexpected keyword 'const'. Const declarations are not supported in strict mode.
仔细查看后,肯定是got 包没有将其const 转换为var。
我不确定要检查什么来解决此问题。
通过一些研究,我发现了一些建议的解决方案,例如:
- 将
--harmony标志添加到我的构建命令中 - 让我的
.babelrc预设读取"presets": ["es2015", "react", "stage-0"] - 已将我的
node_modules排除并包含在我的 webpack 中的 javascript 加载程序中
所有这些都没有帮助。
加载器示例:
{
test: /\.js$/,
loaders: ['babel'],
exclude: /node_modules/, // also tried commenting out this line
include: path.join(__dirname, 'src')
},
【问题讨论】:
-
你是如何加入
node_modules的?你试过include: [path.join(__dirname, 'src'), path.join(__dirname, 'node_modules')])吗? -
@YuryTarabanko 非常有趣。这对我有用!在以这种方式包含我的
node_modules时,我还有什么需要注意的吗? -
在构建步骤中添加更多文件进行转换会牺牲速度。我建议您更具体一些,仅包含来自
node_modules.的got文件夹
标签: javascript node.js npm webpack