Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript ES6 import with @ character

I have folder in node_modules named: @mymodule and inside it there is a folder named 'insidefolder'

Path looks like this: node_modules/@mymodule/insidefolder

Using ES6 syntax I try to import insidefolder in this module:

import insidefolder from '@mymodule/insidefolder';

I get an error: Error: Cannot find module '../ymodule/insidefolder'

const mymodule = require('@mymodule/insidefolder');

Works just fine.

How can it be fixed?

like image 784
Elminday Avatar asked Mar 28 '26 23:03

Elminday


1 Answers

It happens so that my .babelrc had plugin:

["babel-root-import", [{
      "rootPathPrefix": "@",
      "rootPathSuffix": "src"
    }]]

And every import starting with @ pointed to src path. I deleted this and everything works just fine.

like image 87
Elminday Avatar answered Mar 31 '26 03:03

Elminday



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!