我正在使用的应用在Safari上运行时遇到问题(在其他任何地方运行都很好)。在那里,它不会加载我的bundle.js文件,并发出一条错误消息,指出在严格模式下“意外使用了保留字'let'。
我从其他一些问题中看到,这很可能是由于翻译程序问题引起的-但我不是Webpack或Babel的专家,而且我不知道从哪里开始解决此问题。
这是我的webpack配置(公用)文件:
const path = require('path');
const webpack = require('webpack');
module.exports = {
entry: ['babel-polyfill', path.join(__dirname, `/src/main.js`)],
output: {
path: path.join(__dirname, `/public`),
filename: `bundle.js`
},
module: {
rules: [
{
test: /\.js$/,
exclude: [
path.join(__dirname, '/node_modules'),
],
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env', '@babel/preset-react'],
plugins: [
['transform-class-properties', { 'spec': true }],
['transform-object-rest-spread']
]
}
}
}, {
test: /\.s?css$/,
use: [
{ loader: 'style-loader' },
{ loader: 'css-loader' },
{ loader: 'sass-loader' }
]
}
]
}
};
这是我的package.json:
{
"name": "last-minute",
"version": "1.0.0",
"description": "connect to others nearby for last-minute hanging out",
"main": "webpack.prod.js",
"engines": {
"node": "9.5.0",
"npm": "6.1.0"
},
"scripts": {
"test": "jest --config jest.config.json",
"start": "node server/server.js",
"build": "webpack --config webpack.prod.js",
"dev": "webpack --config webpack.dev.js --mode development && node server/server.js",
"light": "webpack --config webpack.light.js --mode development && node light-server/style-server.js"
},
"author": "Doug Sauve",
"license": "ISC",
"dependencies": {
"@babel/core": "^7.0.0-beta.44",
"@babel/preset-env": "^7.0.0-beta.44",
"@babel/preset-react": "^7.0.0-beta.44",
"@google/maps": "^0.4.6",
"babel-loader": "^8.0.0-beta.2",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.7.0",
"bcryptjs": "^2.4.3",
"css-loader": "^0.28.11",
"enzyme": "^3.3.0",
"enzyme-adapter-react-16": "^1.1.1",
"express": "^4.16.2",
"google-maps-react": "^2.0.2",
"jest": "^22.4.4",
"moment": "^2.22.1",
"mongoose": "^5.0.14",
"node-sass": "^4.9.2",
"nodemailer": "^4.6.5",
"normalize.css": "^8.0.0",
"raf": "^3.4.0",
"react": "^16.3.1",
"react-dom": "^16.3.1",
"react-geocode": "0.0.9",
"react-redux": "^5.0.7",
"react-test-renderer": "^16.0.0",
"redux": "^4.0.0",
"sass-loader": "^6.0.7",
"socket.io": "^2.1.0",
"style-loader": "^0.20.3",
"validator": "^10.2.0",
"webpack": "^4.4.1",
"webpack-cli": "^2.0.13",
"webpack-merge": "^4.1.2"
}
}
如果有人可以帮助我,我将感到非常高兴!
答案 0 :(得分:0)
ES6'let'。Can I Use是检查浏览器兼容性的很好资源。
答案 1 :(得分:0)
未经检验的可能性:我将在稍后进行测试,但是,如果您尚未解决此问题,请检查您的.babelrc文件
我今天试图解决与polyfill的兼容性问题,这可能是因为我没有为iOS的较早版本正确配置预设环境 Babel的此页面显示了如何为Safari 7或更高版本配置预设。
https://babeljs.io/docs/en/6.26.3/babel-preset-env
明天睡觉后我会尝试这个的。