.babelrc not working properly


#1

I’m using babel-root-import to specify my app code’s root (I’m aware of the fork by kadira) and it’s working fine with webpack:webpack. My .babelrc is simply

{
  "presets": [
    "react",
    "es2015",
    "stage-0"
  ],
  "plugins": [
    ["babel-root-import", {
      "rootPathSuffix": "src"
    }]
  ]
}

However, this doesn’t work with normal Meteor (ie without webpack:webpack). The error logs are really weird because they suggest the path is computed properly:

// someFile.js
import '~/client/utils.js'; // the file is located at ./src/client/utils.js

will raise:

Unable to resolve some modules:

  "/Users/me/project/src/client/utils.js" in /Users/me/project/src/.../someFile.js (os.osx.x86_64)

and if I do $ /Users/me/project/src/client/utils.js to check, there is a file there indeed.


#2

That looks very much like what I’ve seen from people with the problem reported in issue #7225. StephenBoyd even stated at one point in the issue “The paths shown in the error messages are definitely the correct paths to the files.”

It looks as though Ben’s final word was “This appears to be a problem specific to the misbehavior of the babel-root-slash-import plugin, which means it’s probably best fixed in Mantra (by removing the plugin).” Removing the plugin cured their issues.

Removing the plugin won’t cure yours because you’re actually using the ability to change the root to something other than the root of the project.

I’d suggest going with the flow. Change your import to "import ‘/src/client/utils.js’; and get rid of the plugin. It should work then.


#3

thanks, I’ve added a reproduction to the issue


#4

I have a fork of the plugin that uses relative instead of absolute paths (this is how I got it to work in a Meteor app); you may want to see if that takes care of it for you: https://github.com/nathantreid/babel-root-import

If someFile.js is located in ./src/client/someDir/someFile.js, it’ll transform the import path ~/client/utils.js into ../utils.js instead of /Users/me/project/src/client/utils.js.
I’ve only tested it on Windows but it should be cross-platform compatible.

I haven’t gotten around to updating the tests and submitting a PR yet.