bundle.js:1 语法错误:意外的关键字“const".严格模式不支持 const 声明 [英] bundle.js:1 SyntaxError: Unexpected keyword 'const'. Const declarations are not supported in strict mode

查看:50
本文介绍了bundle.js:1 语法错误:意外的关键字“const".严格模式不支持 const 声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站可以在我的 iPad 和台式机上正常运行,但不能在我在 browserstack.com 上测试的其他设备(例如 iPhone 6S 上的 Safari)和我的 iPhone 4 上运行.

I have a site that works fine on my iPad and desktop, but not on other devices I am testing at browserstack.com (eg Safari on iPhone 6S) and my iPhone 4.

从视觉上看,CSSJS 只是没有加载.

Visually, it just looks like the CSS and JS is just not loading.

浏览器堆栈中的开发工具控制台错误是:

The dev tools console error at browserstack is:

bundle.js:1 语法错误:意外的关键字const".常量严格模式不支持声明.

bundle.js:1 SyntaxError: Unexpected keyword 'const'. Const declarations are not supported in strict mode.

我的 webpack.config.json 有这个规则:

rules: [{
        test: /\.js$/,
        exclude: /(node_modules)/,
        use: {
            loader: "babel-loader",
            options: {
                presets: ["env", "stage-0"]
            }
        }
    },

.babelrc 是:

{
    "presets": [
        "env",
        "stage-0"
    ]
}

并且 package.json 有:

"devDependencies":
{
    "babel-cli": "^6.26.0",
    "babel-core": "^6.26.3",
    "babel-loader": "^7.1.4",
    "babel-preset-env": "^1.7.0",
    "babel-preset-stage-0": "^6.24.1",
    "css-loader": "^0.28.11",
    "expose-loader": "^0.7.5",
    "file-loader": "^1.1.11",
    "less": "^3.0.4",
    "less-loader": "^4.1.0",
    "style-loader": "^0.21.0",
    "uglifyjs-webpack-plugin": "^1.2.5",
    "uikit": "^3.0.0-rc.16",
    "url-loader": "^1.0.1",
    "webpack": "^4.19.1",
    "webpack-cli": "^2.1.5"
}

推荐答案

可能的解决方案:

你已经在 babel-loader 设置中排除了node_modules",所以它不会处理您的外部依赖项.你依赖的这个包可能未针对浏览器内使用情况进行测试.

You've excluded "node_modules" in babel-loader settings, so it doesn't process your external dependencies. This package you depend on probably is not tested for in-browser usage.

https://stackoverflow.com/a/34039372

结果:

我注释掉了 webpack.config.json 中的 exclude:/(node_modules)/, 行,站点 似乎 可以正常工作(我仍在测试所有设备/浏览器).我有点担心这个解决方案,因为我首先排除 node_modules 肯定是有原因的,但我不记得为什么:(.

I commented out the exclude: /(node_modules)/, line in webpack.config.json and the site seems to be working (i'm still testing all devices/browsers). I'm a bit concerned with this solution though as there must have been a reason why i was excluding node_modules in the first place, but i can't remember why :(.

这篇关于bundle.js:1 语法错误:意外的关键字“const".严格模式不支持 const 声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆