背景:
我正在使用 Nextjs 构建一个 React 应用程序。我正在尝试添加第三方库 @typeform/embed
问题 但是,我无法构建导入 @typeform/embed
的页面。因为 babel 问题。似乎我可以在我编写的页面上使用 es6 语法,但是因为它位于 node_modules 文件夹中,所以会引发错误。
我的尝试
尽管关注了其他一些帖子并添加了 @babel/preset-env
和 @babel/plugin-transform-runtime
错误
ReferenceError: regeneratorRuntime is not defined
at /Users/xxx/yyy/node_modules/@typeform/embed/build/lib.pure.js:1:41461
at Object.o.m.i (/Users/xxx/yyy/node_modules/@typeform/embed/build/lib.pure.js:1:42577)
at o (/Users/xxx/yyy/node_modules/@typeform/embed/build/lib.pure.js:15:2951)
at Object.o.m.i (/Users/xxx/yyy/node_modules/@typeform/embed/build/lib.pure.js:1:19285)
at o (/Users/xxx/yyy/node_modules/@typeform/embed/build/lib.pure.js:15:2951)
at Module.o.m.i (/Users/xxx/yyy/node_modules/@typeform/embed/build/lib.pure.js:1:44165)
at o (/Users/xxx/yyy/node_modules/@typeform/embed/build/lib.pure.js:15:2951)
at /Users/xxx/yyy/node_modules/@typeform/embed/build/lib.pure.js:15:2855
at /Users/xxx/yyy/node_modules/@typeform/embed/build/lib.pure.js:1:81
at Object.<anonymous> (/Users/xxx/yyy/node_modules/@typeform/embed/build/lib.pure.js:1:322)
// babel.config.js
module.exports = {
presets: [
"@babel/preset-env",
[
"@babel/preset-react",
{
runtime: "automatic",
},
],
],
plugins: ["@babel/plugin-transform-runtime"],
// fullcalendar attempts to import its own CSS files, but next.js does not allow this.
// throw away these statements before they arrive at next.js,
// but you'll need to import them manually in pages/_app.jsx.
// will also work for any other 3rd-party packages that attempt to do this.
overrides: [
{
include: ["./node_modules"],
plugins: [
[
"babel-plugin-transform-require-ignore",
{
extensions: [".css"],
},
],
"@babel/plugin-proposal-nullish-coalescing-operator",
],
},
],
}
//package.json
"devDependencies": {
"@babel/core": "^7.12.13",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.12.13",
"@babel/plugin-transform-runtime": "^7.12.15",
"@babel/preset-env": "^7.12.16",
"@babel/preset-react": "^7.12.13",
}