Elminday
Elminday

Reputation: 73

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?

Upvotes: 3

Views: 1234

Answers (1)

Elminday
Elminday

Reputation: 73

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.

Upvotes: 2

Related Questions