gpt4 book ai didi

reactjs - nextjs ie11 预期标识符

转载 作者:行者123 更新时间:2023-12-04 15:03:16 30 4
gpt4 key购买 nike

我一直在 Chrome 上开发,希望 Babel 能简单地适合我的代码,即

出现一个错误SCRIPT1010: Expected identifier
Internet Explore 将错误指向此处(此文件位于静态/ block 中)。

{isClean:a}

...,e,r){"use strict";let n,i,o,s=r("dUwI"),{isClean:a}=r("zomH"),u=r( "aOxJ"),c=r("wWcZ");class l extends...

我尝试添加 polifills在我的 app.js 中

import 'core-js/stable' // core-js@3 not @2
import 'promise-polyfill/src/polyfill' // core-js@3 not @2
import 'whatwg-fetch'
import 'url-polyfill'
import assign from 'object-assign'
Object.assign = assign

import 'react-app-polyfill/ie9';
import 'react-app-polyfill/ie11';
import 'react-app-polyfill/stable';
import "es6-shim"

但它仍然给我同样的错误

我不知道为什么会出现这个错误,但如果 Babel 正确地翻译了我的代码,这可能是 babel 不关心的 node_modules 中的代码。但我的问题是我什至不知道哪个模块包含问题。

告诉我我需要做什么才能挖掘更多。我完全迷失了

我没有用 .babelric 文件配置任何东西,它默认是带有 typescript 的 next.js

我试过了

<Head >
<meta http-equiv="x-ua-compatible" content="IE=edge" />
</Head>

我只需要更多调试消息.. 来找出确切的问题。

我真的很沮丧,作为一名开发人员,我已经努力工作了 3 年,但有太多事情要担心。一旦解决了这些项目,我将退出开发人员。...并完成更简单的工作。

添加

我只能在构建后用ie打开屏幕,所以我总是构建并重新开始调试。

当我在 nanoid 模块中运行开发模式时(我没有自己安装这个模块。我不确定这个错误是否与我在构建后得到的错误相同。)
错误点箭头函数...

let customAlphabet = (alphabet, size) => {
return () => {

我的package.json浏览器列表

"browserslist": {
"production": [
"ie 11"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version",
"ie 11"
]
}

和corejs版本

"core-js": "^3.9.1",

现在我正试图删除我的大部分代码。 (我做到了)但我仍然可以看到同样的错误

也许这不是我安装的模块或我编写的代码的问题....

ADD2
不,不是我删除了几乎所有代码,错误就消失了我的代码中有一些东西......

ADD3

谢谢解答
我现在可以阅读 block 代码了
即表示问题是
{ isClean }

(window["webpackJsonp_N_E"] = window["webpackJsonp_N_E"] || []).push([[6],{

/***/ "+9U2":
/***/ (function(module, exports, __webpack_require__) {

"use strict";

let Declaration = __webpack_require__("dUwI")
>>>>>>let { isClean } = __webpack_require__("zomH")
let Comment = __webpack_require__("aOxJ")
let Node = __webpack_require__("wWcZ")

是的,我仍然不知道哪个模块是,但是
但现在我试图逐行删除代码。我想我很快就会知道的。

#Add4我一行一行地打扫,结果它在转圈😥😥。
我的下一个作品将使用
next-transpile-modules 侮辱每个 node_modules 看看会发生什么......我把每个节点模块都放在 next-transpile-modules 但结果是一样的let 不要更改为 var

#Add5最后我找到了导致这个问题的模块是“sanitize-html”模块没有错。只是我没有正确阅读文档。这是服务端使用的模块,但是我用在客户端...

感谢帮助我的 StackOverflow 人员..!!

最佳答案

据我所知,你的包有 class 声明,而 IE 不理解它们。 Polyfills 不会有帮助,因为你不能 polyfill 这样的东西,它应该被转换成兼容的 ES5 代码。它可能是您使用的某些库的一部分,因此您需要使用 next-transpile-modules NextJs 转译这个库的 node_modules 代码的事情。

使用示例:

// next.config.js

// pass the modules you would like to see transpiled
const withTM = require('next-transpile-modules')(['somemodule', 'and-another']);

module.exports = withTM();

还有一个说明如何找到导致问题的包:

  • add config.optimization.minimize = false; to you next.config.js's Webpack configuration
  • run a production build
  • run it on the browser throwing the error
  • open the console, jump to the line where it failed
  • goes a little bit up in the lines of code, and check the Webpack comments telling you which module is affected

https://github.com/martpie/next-transpile-modules#how-do-i-find-out-which-package-is-causing-a-runtime-exception

关于reactjs - nextjs ie11 预期标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66595712/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com