我有任务-在工作的nodeJs项目中将node版本从12升级到16。节点升级后,其中一个存储库(在monorep中)开始在部署过程中失败。错误:
ERROR in <my project>/node_modules/@sailplane/injector/dist/esm/injector.js 197:23
Module parse failed: Unexpected token (197:23)
File was processed with these loaders:
* ../../node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
| return function (target) {
| let asName = undefined;
> if (typeof options?.as === "function") {
| // Validate that 'as' is a parent class
| let found = false;
@ ./src/discovery-gql.ts 1:0-47 20:25-33
正如你所看到的,它在node_modules中失败,并建议我为webpack使用适当的加载器。我当前的加载器(webpack.sls.config.js):
...
module: {
rules: [
{
test: /(?!:spec)\.tsx?$/,
loader: 'ts-loader',
exclude: /\.d\.ts$/,
},
{
test: /\.d\.ts$/,
loader: 'ignore-loader',
},
{
test: /\.mjs$/,
type: "javascript/auto"
},
{
test: /\.js$/, //this one I just added
loader: 'babel-loader',
},
],
},
...
添加babel-loader后错误没有消失。为什么在node_modules / dist级别失败?我该怎么办?
1条答案
按热度按时间xjreopfe1#
是什么帮助了我:添加加载器:
并将plagins添加到babel: