NextJS 5 应用程序中意外的令牌导出
我正在尝试在 NextJS 5 应用程序中使用 date-holidays
npm 包。该包依赖于另一个名为 astronomia
的包。我正在使用 Babel 6。当我构建应用程序时,它会抛出以下错误。
/app/node_modules/astronomia/data/vsop87Bearth.js:2611
export default m;
^^^^^^
SyntaxError: Unexpected token export
at Module._compile (internal/modules/cjs/loader.js:723:23)
at Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Object.require.extensions.(anonymous function) [as .js] (/Users/irfan/Projects/sourcetree/swapwise/swapwise-web-app/node_modules/babel-register/lib/node.js:152:7)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (/Users/irfan/Projects/sourcetree/swapwise/swapwise-web-app/node_modules/date-holidays-parser/lib/vsop87Bearth.cjs:5:21)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Object.require.extensions.(anonymous function) [as .js] (/Users/irfan/Projects/sourcetree/swapwise/swapwise-web-app/node_modules/babel-register/lib/node.js:152:7)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
我的 .babelrc
内容如下:
{
"presets": ["next/babel"],
"plugins": [
["module-resolver", { "root": ["./"] }]
]
}
我不知道如何让 babel 转译 vsop87Bearth.js
和 data 文件夹下的其他 js 文件。我尝试在不同的地方使用 preset-env
但没有任何效果。我不确定是否需要使用预设环境,因为我使用的是 Next 5。
我在 package.json 的脚本中使用 es2015
和 stage-2
预设
"nodemon --exec cross-env NODE_ENV=development BUILD_ENV=dev NODE_TLS_REJECT_UNAUTHORIZED=0 babel-node server --presets env es2015 stage-2"
任何帮助将不胜感激。
I am trying to use date-holidays
npm package in my NextJS 5 application. This package has a dependency on another package called astronomia
. I am using Babel 6. When I build the application it throws the following error.
/app/node_modules/astronomia/data/vsop87Bearth.js:2611
export default m;
^^^^^^
SyntaxError: Unexpected token export
at Module._compile (internal/modules/cjs/loader.js:723:23)
at Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Object.require.extensions.(anonymous function) [as .js] (/Users/irfan/Projects/sourcetree/swapwise/swapwise-web-app/node_modules/babel-register/lib/node.js:152:7)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (/Users/irfan/Projects/sourcetree/swapwise/swapwise-web-app/node_modules/date-holidays-parser/lib/vsop87Bearth.cjs:5:21)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Object.require.extensions.(anonymous function) [as .js] (/Users/irfan/Projects/sourcetree/swapwise/swapwise-web-app/node_modules/babel-register/lib/node.js:152:7)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
The contents of my .babelrc
are as follow:
{
"presets": ["next/babel"],
"plugins": [
["module-resolver", { "root": ["./"] }]
]
}
I am not sure how to get babel to transpile vsop87Bearth.js
and other js files under data folder. I have tried using preset-env
in various places but nothing worked. I am not sure that I even need to use preset-env since I am using Next 5.
I am using es2015
and stage-2
presets in a script in package.json
"nodemon --exec cross-env NODE_ENV=development BUILD_ENV=dev NODE_TLS_REJECT_UNAUTHORIZED=0 babel-node server --presets env es2015 stage-2"
Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论