Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mocha, Babel, and Windows symlinks #9824

Open
ricick opened this Issue Apr 5, 2019 · 1 comment

Comments

Projects
None yet
2 participants
@ricick
Copy link

commented Apr 5, 2019

Bug Report

Current Behavior
Mocha is not running Babel beforehand when the project is behind a symlink on windows.

I have a small SSD and a larger HDD so to make my life easier I have a hard symlink to D:/projects in C:/Users/MyUser home directory, so can access via ~/projects.

When running mocha --require @babel/register I'm getting the Unexpected identifier import problem. I even re-installed windows thinking it might be an environment problem before figuring out that this was the problem

Input Code
Create a simple mocha es6 project in realfoldercontainer/myproject, to be run via npm test with mocha -r @babel/register in package.json

Create a hard symlink with mklink /j linkname realfoldercontainer

Navigate to linkname/myproject

Run npm test

Expected behavior/code

npm test

> mochatest@1.0.0 test D:\projects\mochatest
> mocha -r @babel/register

  index test
    sayHello function
      √ should say Hello guys!


  1 passing (44ms)

Actual behavior

npm test

> mochatest@1.0.0 test D:\testlink\mochatest
> mocha -r @babel/register

D:\projects\mochatest\test\index.test.js:3
import sayHello from "../src/index"
       ^^^^^^^^

SyntaxError: Unexpected identifier
    at Module._compile (internal/modules/cjs/loader.js:749:23)
    at Module._compile (D:\projects\mochatest\node_modules\pirates\lib\index.js:99:24)
    at Module._extensions..js (internal/modules/cjs/loader.js:816:10)
    at Object.newLoader [as .js] (D:\projects\mochatest\node_modules\pirates\lib\index.js:104:7)
    at Module.load (internal/modules/cjs/loader.js:672:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:612:12)
    at Function.Module._load (internal/modules/cjs/loader.js:604:3)
    at Module.require (internal/modules/cjs/loader.js:711:19)
    at require (internal/modules/cjs/helpers.js:14:16)
    at D:\projects\mochatest\node_modules\mocha\lib\mocha.js:327:36
    at Array.forEach (<anonymous>)
    at Mocha.loadFiles (D:\projects\mochatest\node_modules\mocha\lib\mocha.js:324:14)
    at Mocha.run (D:\projects\mochatest\node_modules\mocha\lib\mocha.js:801:10)
    at Object.exports.singleRun (D:\projects\mochatest\node_modules\mocha\lib\cli\run-helpers.js:207:16)
    at exports.runMocha (D:\projects\mochatest\node_modules\mocha\lib\cli\run-helpers.js:300:13)
    at Object.exports.handler.argv [as handler] (D:\projects\mochatest\node_modules\mocha\lib\cli\run.js:296:3)
    at Object.runCommand (D:\projects\mochatest\node_modules\yargs\lib\command.js:238:44)
    at Object.parseArgs [as _parseArgs] (D:\projects\mochatest\node_modules\yargs\yargs.js:1089:24)
    at Object.parse (D:\projects\mochatest\node_modules\yargs\yargs.js:566:25)
    at Object.exports.main (D:\projects\mochatest\node_modules\mocha\lib\cli\cli.js:62:6)
    at Object.<anonymous> (D:\projects\mochatest\node_modules\mocha\bin\_mocha:10:23)
    at Module._compile (internal/modules/cjs/loader.js:805:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:816:10)
    at Module.load (internal/modules/cjs/loader.js:672:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:612:12)
    at Function.Module._load (internal/modules/cjs/loader.js:604:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:868:12)
    at internal/main/run_main_module.js:21:11
npm ERR! Test failed.  See above for more details.

Babel Configuration (.babelrc, package.json, cli command)

{
  "your": { "config": "here" }
}

Environment
node v11.13.0

"@babel/cli": "^7.4.3",
"@babel/core": "^7.4.3",
"@babel/node": "^7.2.2",
"@babel/preset-env": "^7.4.3",
"@babel/register": "^7.4.0",
"chai": "^4.2.0",
"jest": "^24.7.1",
"mocha": "^6.0.2"

Additional context/Screenshots
I can now corretctly run the tests by going directly to the folder, but it took a long time to figure this out, including a system rebuild to try and fix the problem.

I'm unsure as to whether this is a babel or mocha issue, so will be posting in both github issues pages.

@babel-bot

This comment has been minimized.

Copy link
Collaborator

commented Apr 5, 2019

Hey @ricick! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community
that typically always has someone willing to help. You can sign-up here
for an invite.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.