0

I have task - to upgrade node version from 12 to 16 in working nodeJs project. After node upgrade one of repositories (in monorep) started to fails in deploy process. Error:

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

As you can see it fails in node_modules and suggests me to use proper loaders for webpack. My current loaders(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',
      },
      
    ],
  },
...

Error doesn't disappeared after adding babel-loader. Why it fails in node_modules / dist level? What should I do?

  • Does this answer your question? ["You may need an additional loader to handle the result of these loaders."](https://stackoverflow.com/questions/63423384/you-may-need-an-additional-loader-to-handle-the-result-of-these-loaders) – undefined Jun 24 '23 at 17:18
  • No, It didn't help me. – Nikita Polevoi Jun 24 '23 at 20:58

1 Answers1

0

What helped me: added loader:

   {
        test: /\.js$/,
        exclude: /node_modules\/(?!(@sailplane\/injector)\/).*/,
        use: {
          loader: 'babel-loader',
        },
      }

and added plagins to babel:

 plugins: [
        '@babel/plugin-proposal-optional-chaining',
        '@babel/plugin-proposal-nullish-coalescing-operator'
      ],