- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
PS:这是我第一次放弃在这里撰写第一个问题。如果有人可以提供帮助,我将非常感激。谢谢!
我正在尝试在相对较旧的 iPad 上的 iOS 10 Safari 中加载我的 ReactJS Web 应用程序(我使用 webpack 和 babel-loader,并使用 webpack-dev-server 提供服务)。
我收到以下语法错误:
语法错误:意外的标记“...”。需要一个属性名称。
(该页面在我迄今为止尝试过的所有设备/浏览器上都能正常加载。)
该错误是由这行转译代码引起的:
eval("\nconst publicIp = __webpack_require__(/*!public-ip */\"./node_modules/public-ip/browser.js\");\n\nconst isOnline = 异步选项 => {\n\t选项 = {\n\t\t超时:5000,\n\t\t版本:'v4',\n\t\t...选项\n\t};\n\n\ttry {\n\t\tawait publicIp[options.version](options);\n\t\treturn true;\n\t} catch (_) {\n\t\treturn false;\n\t}\n} ;\n\nmodule.exports = isOnline;\n//TODO:在下一个主要版本中删除此\nmodule.exports.default = isOnline;\n\n\n//# sourceURL=webpack:///./node_modules/is-online/browser.js?");
我们可以在源 https://github.com/sindresorhus/is-online/blob/master/browser.js 中观察到:
const isOnline = async options => {
options = {
timeout: 5000,
version: 'v4',
...options
};
// ...
};
在我看来,不支持使用 ...
扩展运算符进行对象解构。该代码来 self 正在使用的名为“is-online”的 npm 模块。
我尝试将“@babel/plugin-transform-destructuring”插件添加到 .babelrc
中,看看是否可以解决这个问题。所有内容都已编译,但这部分代码是相同的,因此仍然产生相同的错误。
我发现这个 Twitter 对话描述了同样的问题,而且也涉及 Safari,但他设法解决了这个问题,因为他“还需要为其激活转换插件:transform-object-rest-spread”:
https://twitter.com/beberlei/status/984083670012256258
所以我尝试了一下,但没有成功。
然后我在 .babelrc
中加强了我的插件游戏,并在网上搜索类似案例,尝试不同的配置,使用 npx babel-upgrade
更新 babel,删除并重新安装node_modules
并将插件直接放入 module.rules[0].options.plugins
我放弃了:
// .babelrc
{
"presets": [
"@babel/preset-env",
"@babel/preset-react"
],
"plugins": [
"@babel/plugin-transform-spread",
"@babel/plugin-transform-destructuring",
"@babel/plugin-transform-parameters",
"@babel/plugin-proposal-object-rest-spread",
]
}
...但它仍然给出错误。它还尝试将“@babel/plugin-transform-runtime”放在那里:相同。
我现在的 webpack 配置:
// webpack.dev.js
const path = require("path");
const webpack = require("webpack");
const TerserPlugin = require('terser-webpack-plugin');
module.exports = [
// App
{
mode: 'development',
entry: {
app: "./src/index.js"
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /(node_modules|bower_components)/,
loader: "babel-loader",
options: {
presets: ["@babel/env"],
}
},
{
test: /\.css$/,
use: ["style-loader", "css-loader", "postcss-loader"]
},
{
test: /\.(png|svg|jpg|gif)$/,
use: [
'file-loader'
]
}
]
},
resolve: { extensions: ["*", ".js", ".jsx"] },
output: {
filename: "app-v0.9.6.js",
path: path.resolve(__dirname, "public/dist/"),
publicPath: "/dist/"
},
plugins: [new webpack.HotModuleReplacementPlugin()],
devServer: {
host: '0.0.0.0',
disableHostCheck: true,
port: 80,
contentBase: path.join(__dirname, "public/"),
publicPath: "http://localhost:3000/dist/",
hotOnly: true
},
// Fixes Safari 10-11 bugs
// Has nothing to do with this question: already tried to comment this out
optimization: {
minimizer: [new TerserPlugin({
terserOptions: {
safari10: true,
},
})],
},
},
// Library
{
mode: 'development',
// ...
// another output that's exposed as a global variable (library)
}
];
以下是开发依赖项:
// package.json
...
"devDependencies": {
"@babel/cli": "^7.5.5",
"@babel/core": "^7.5.5",
"@babel/plugin-proposal-object-rest-spread": "^7.0.0",
"@babel/plugin-transform-destructuring": "^7.0.0",
"@babel/plugin-transform-parameters": "^7.0.0",
"@babel/plugin-transform-runtime": "^7.5.5",
"@babel/plugin-transform-spread": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/preset-react": "^7.0.0",
"babel-loader": "^8.0.6",
"babel-preset-env": "^1.7.0",
"css-loader": "^3.2.0",
"file-loader": "^4.2.0",
"html-webpack-plugin": "^3.2.0",
"postcss-loader": "^3.0.0",
"style-loader": "^0.23.1",
"webpack": "^4.39.1",
"webpack-cli": "^3.3.6",
"webpack-dev-server": "^3.8.0",
"webpack-merge": "^4.2.1"
},
...
如果有人知道如何正确配置它,我将不胜感激。
最佳答案
正如您所理解的,您导入的模块中使用的“对象字面量中的 ES2018 扩展语法”(又名省略号)正在泄漏到您的转译包中,从而扰乱了最可怜的浏览器。发生这种情况的原因是:
Webpack 设置为忽略您的 node_modules,因此 is-online 不会被转译。
这是一个适合您的实用解决方案 - 修改 webpack.config.js
的 exclude
规则,如下所示:
exclude: /(node_modules\/(?!is-online)|bower_components)/,
又名。 “排除 Bower_Components 和除 is-online 之外的所有 Node_modules”
以防万一 -要排除更多模块,请写入:
exclude: /(node_modules\/(?!is-online|another-es6-module|yet-another-one)|bower_components)/,
可能还有更漂亮的表达方式;如果你是审美家,试试你的运气 here .
完成后,检查输出文件中是否有字符串“...”。希望它消失了!
如果您喜欢,您可以在每次构建后自动检查“...”的输出,以确保不会错过任何模块。但话又说回来,它会在包含省略号的合法字符串文字上触发......
唷!我差点以为other forces were at play ...
<小时/>由于问题错误而导致的旧响应:
您的粗箭头函数返回一个未括在括号中的对象文字。
Returning object literals
Keep in mind that returning object literals using the concise body syntax
params => {object:literal}
will not work as expected.var func = () => { foo: 1 };
// Calling func() returns undefined!
var func = () => { foo: function() {} };
// SyntaxError: function statement requires a nameThis is because the code inside braces (
{}
) is parsed as a sequence of statements (i.e.foo
is treated like a label, not a key in an object literal).You must wrap the object literal in parentheses:
var func = () => ({ foo: 1 });
关于reactjs - 通天塔 : can't get "@babel/plugin-transform-destructuring" plugin to work,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57444395/
有 destructuring-bind 但似乎没有 destructuring-setq。是否可以使用 destructuring-bind 来定义它? (let (a b c d) (dest
我遇到了一个我无法解决的丑陋问题。我是 React 的初学者。 这是我的代码 handleCheckChildElement(event) { let items = this.state.i
在 React 项目中,我想通过在特定时间记录特定状态部分来快速解决问题。 console.error('this.state.thing', this.state.thing); 这样做,我的 ES
hylang 是否像 clojure 中那样支持映射解构? 例如:https://gist.github.com/john2x/e1dca953548bfdfb9844#maps 最佳答案 Hy 没有
我正在尝试解构绑定(bind),如下所示: (destructuring-bind (a b) '(1 2) (list a b))) 当我在 REPL 中评估它时,我得到:
我已启用 SeriLog(最新版本)自记录功能,并且看到数百条消息说 Maximum destructuring depth reached 不知道这意味着什么以及这是否是我需要担心的问题。 有谁知道
我正在编写一个小型 React Native 应用程序,并且正在尝试使用 Flow,但我无法在任何地方真正获得有关它的正确教程。 我不断收到错误:关于此代码第一行中的 ({ station }) 的解
在 modules 文件夹中设置 redux 文件: \modules \application \actions application.js
我收到 JavaScript 错误 "missing = in destructuring declaration" 可能是什么问题? 最佳答案 这不是标准的 JavaScript 错误。它来自您的编
我正在使用一些像这样的解构: const { item } = content console.log(item) 但是我应该如何处理 content === undefined - 这会引发错误?
法拉第扫描函数的来源( https://github.com/ptaoussanis/faraday/blob/master/src/taoensso/faraday.clj#L1197 )有一个我正
我应该如何重写以下行以避免出现此错误 ctrl.formData.type = ctrl.types[0]; 最佳答案 根据 prefer-destructuring docs 调整规则配置应该避免这
有没有办法把下面的代码写得短一些? const { user } = JWT.verify(req.params.token, keys.secretOrKey); const { email } =
以下代码: export const myFunction = ({ option1, option2 }) => {}; ...给出: destructuring. Missing annotati
我有这个功能: const calculateTotal = (items) => { return items.reduce((totalPrice, basketItem) => {
我试图将应用程序下的所有组件包装在一个上下文中以提供我想要的东西 (如您所见,这是我的 UserContext 组件) enter code here import React, { useStat
这段代码有什么问题吗? class App extends React.Component { constructor(props) { super(props); this.st
我正在尝试编写一个宏,该宏扩展为具有解构的 let 形式。我的问题是我想拥有以 let 形式定义的符号列表,包括通过解构获得的符号列表。 用例 我试图排除这种行为,例如验证: (let [a (foo
嘿,我有这样的 uiTypes.js 文件: export default { SELECT_ITEM: 'SELECT_ITEM', DESELECT_ITEM: 'DESELECT_ITE
刚刚开始使用 Flow,但似乎无法理解它希望我为解构对象(例如 props)添加类型来做什么 即 render({ count }, { displayHelp }) { 抛出类似的错误 16:
我是一名优秀的程序员,十分优秀!