internet-explorer - Gatsby JS - 生成 SSR 包失败
问题描述
我在让 Gatsby 在 IE11 下以开发模式工作时遇到问题。当我执行npm start 时,出现以下错误:
ERROR #98123 WEBPACK
Generating SSR bundle failed
.cache\develop-static-entry.js: Unexpected token, expected "," (31:10)
29 | export default (pagePath, callback) => {
30 | let headComponents = [
> 31 | <meta key="environment" name="note" content="environment=development" />,
| ^
32 | ]
33 | let htmlAttributes = {}
34 | let bodyAttributes = {}
File: .cache\develop-static-entry.js:31:10
这就是我的 .babelrc 文件的外观
{
"plugins": [
["@babel/plugin-proposal-decorators", { "legacy": true }],
["@babel/plugin-transform-arrow-functions"],
["@babel/plugin-transform-object-super"],
["@babel/plugin-transform-classes"],
["@babel/plugin-transform-react-jsx"],
["@babel/plugin-transform-typescript"]
],
"presets": [["babel-preset-gatsby-package"]]
}
这是 gatsby-cli 的版本
"gatsby-cli": "^2.12.99",
我尝试了很多方法,但无法找到解决方案。
解决方案
这是一个非常广泛的问题,缺乏试验。IE 回退可能因无限原因和代码片段而失败。在尝试为 IE11 调试一些有问题的代码时,请尝试在您的 中添加以下代码段.babelrc
:
{
"plugins": [
["@babel/plugin-proposal-decorators", { "legacy": true }],
["@babel/plugin-transform-arrow-functions"],
["@babel/plugin-transform-object-super"],
["@babel/plugin-transform-classes"],
["@babel/plugin-transform-react-jsx"],
["@babel/plugin-transform-typescript"]
],
"presets": [
[
"@babel/preset-env",
{
"useBuiltIns": "usage",
"corejs": 2
}
],
[
"babel-preset-gatsby",
{
"targets": {
"browsers": [
">0.25%",
"not dead"
]
}
}
]
],
}
您似乎缺少 Gatsby 的一些 Babel 预设:
babel-preset-gatsby
babel-preset-env
: 这可能不是必需的,如果编译失败则省略它。babel-preset-gatsby-package
: 似乎是不推荐使用的依赖项babel-preset-gatsby
,如果它导致问题,请将其删除。
npm
通过or安装它们yarn
并使用它们。
或者,您可以尝试将以下代码段添加到您的gatsby-node.js
:
exports.onCreateWebpackConfig = function onCreateWebpackConfig({ actions, stage, loaders }) {
if (stage === 'develop') {
actions.setWebpackConfig({
module: {
rules: [
{
test: /react-hot-loader/,
use: [
loaders.js()
]
}
]
}
})
}
}
来源:https ://github.com/gatsbyjs/gatsby/issues/14502 (您可以按照其他解决方法)
推荐阅读
- api - 是否可以进行 API 调用以在 Google My Business API 中使用 [不发布] 各种参与餐厅的菜单?
- sql-server - 有没有办法在更新字段时更改列的其他字段?
- jquery - 从 Google 地图自定义标记的信息窗口中删除关闭标题属性
- javascript - rxjs 可观察管道内的建模和 if/else 模式
- tensorflow - TensorFlow 2.0中Graph可视化的简单案例
- react-native - 为什么独立的 react-native 应用程序不起作用但在 Expo Client 上运行良好?如何解决?
- ansible - 如何使用 Ansible Vault 加密变量?
- java - 如何处理文本区域中的多个字符串
- c# - PasswordSignInAsync() 和 MaxFailedAccessAttempts 究竟是如何连接的?
- loops - SVG.js如何循环多个动画步骤