There is own module with not translated code which lies in node_modules. The following is written in the webpack config:

{ test: /\.js$/, loaders: ['babel'], exclude: /node_modules/ } 

I would like to exclude transpiling everything in node_modules except for my module. For this, I wrote the following:

 exclude: /node_modules(?!\/my_module)/ 

But I did not get the desired result. When you start the application, an error pops up

Uncaught SyntaxError: Unexpected token import (...)

Swears on index.js, in which the necessary components are connected via import.

I tried to bring my module out of the node_modules folder and set the direct path to it in the application.

Instead of import { someComponent } from 'my_module' I wrote the following import { someComponent } from '../my_module' . Naturally, 'my_module' rendered from node_modules to the correct directory.

In theory, now the restriction on transpilation, which is written in the webpack should not apply to my module. But, for some reason, the error does not disappear. As before, the code is not transpiled and the compiler swears at an import unknown to it. What to do?

  • In general, you need more information. Can help: package.json, full config, whether files are transported without es6-imports - Duck Learns to Hide
  • Is this the case that you do not do it on Windows? - ruslik
  • @ruslik on Windows - Ivan Afanasyev
  • @ruslik, and where does the Windows-not Windows? It works great with Windows, and not with me alone. - Duck Learns to Take Cover
  • I just had a similar problem popped up with Unexpected token import - it turned out that the paths are incorrectly spelled because of the backslash, which is in Windows \ and Linux - / - ruslik

0