Skip to content
This repository has been archived by the owner on Feb 18, 2023. It is now read-only.

Not working under Babel 6.14 with register-hook #13

Closed
JonathanRoyGagnon opened this issue Aug 25, 2016 · 6 comments
Closed

Not working under Babel 6.14 with register-hook #13

JonathanRoyGagnon opened this issue Aug 25, 2016 · 6 comments
Assignees
Labels

Comments

@JonathanRoyGagnon
Copy link

Hi,
The plugin is not working when used with babel 6.14 register-hook.

Error: Cannot find module './src/component/server'
    at Function.Module._resolveFilename (module.js:440:15)
    at Function.Module._load (module.js:388:25)
    at Module.require (module.js:468:17)
    at require (internal/module.js:20:19)

The call is in [project]/src/component/auth/auth.middleware.test.js

The plugin has been broken by the following merge : https://github.com/babel/babel/pull/3608/files
Discussion about the pull request : babel/babel#3608

My .babelrc

{
  "presets": ["node6", "stage-0"],
  "plugins": [
    "transform-runtime",
    "babel-plugin-transform-decorators-legacy",
    [ "babel-project-relative-import" , { "sourceDir": "src" }]
  ]
}

Broken test example :

//.babelrc
{
  "presets": ["latest"],
  "plugins": [
    [ "babel-project-relative-import" , { "sourceDir": "a" }]
  ]
}

// main.js
require('babel-core/register');
require('./a/c/c.js');

// a/b/b.js
console.log('hello');

// a/c/c.js
import '~/b/b.js';

// package.json
{
  "name": "test",
  "version": "0.0.0",
  "dependencies": {},
  "devDependencies": {
    "babel-cli": "^6.14.0",
    "babel-core": "^6.14.0",
    "babel-preset-latest": "^6.14.0",
    "babel-project-relative-import": "^2.0.0"
  },
  "engines": {
    "node": ">=6.3.0"
  },
  "private": true
}

Run node main.js

@per2plex per2plex added the bug label Aug 26, 2016
@per2plex per2plex self-assigned this Aug 26, 2016
@per2plex
Copy link
Owner

per2plex commented Aug 26, 2016

Yeah, sourceRoot being set automatically to the dirname of the file breaks the current implementation. A temporary fix in your project would be settings sourceRoot to process.cwd() manually in whichever babel wrapper you use.

Or if you use the babel-cli directly: babel --source-root $(pwd)

I'll rewrite the plugin soon and the sourceDir option will be replaced by babel's sourceRoot option, so setting sourceRoot will be required anyway in the future (probably).

See: #12

@JonathanRoyGagnon
Copy link
Author

Thanks for the fast reply!
I'm eagerly waiting the new version ^^.
Just for information, setting source-root directly in the register-hook configuration doesn't seems to work as the new option is overridden by babel. It might be an overlook from the babel guys.

@per2plex
Copy link
Owner

per2plex commented Sep 7, 2016

Seems you were right (babel/babel#3685). Thanks for notifying them about this issue. Does the temporary fix work now?

@JonathanRoyGagnon
Copy link
Author

I haven't test yet. The latest revision (6.15) does not have the modification (it has been added after). I will give feedback as soon as the new babel revision is out.

@per2plex
Copy link
Owner

I released a beta version under the NPM tag beta which does not use babel's sourceRoot option anymore and replaces it with a custom projectRoot option which defaults to process.cwd, so in your case it should just work.

@JonathanRoyGagnon
Copy link
Author

JonathanRoyGagnon commented Oct 8, 2016

It now works under babel 6.16, I added this overwrite in my gulpfile :

require('babel-register')({
  sourceRoot: process.cwd()
});

Thanks for this plugging, it is the only one working exactly how I want it to ^^.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants