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 and Babel 7 register not found #10777

Closed
gear4s opened this issue Nov 29, 2019 · 6 comments
Closed

Mocha and Babel 7 register not found #10777

gear4s opened this issue Nov 29, 2019 · 6 comments
Labels
i: bug i: needs triage outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@gear4s
Copy link

gear4s commented Nov 29, 2019

Bug Report

Current Behavior
Mocha can't find module
✖ ERROR: Cannot find module '@babel/register'

Input Code

  • REPL or Repo link if applicable:

Expected behavior/code
Mocha should require @babel/register

Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)

  • Filename: babel.config.js
{
	plugins: [
		"@babel/transform-arrow-functions",
		"@babel/proposal-optional-chaining",
		"@babel/proposal-export-default-from",
		"@babel/proposal-class-properties",
		"require-context-hook"
	],

	presets: [
		[
			"@babel/env",
			{
				targets: {
					node: "10"
				},
				useBuiltIns: "usage",
				corejs: 3
			}
		]
	]
}

Environment

  System:
    OS: Linux 5.3 Arch Linux
  Binaries:
    Node: 10.17.0 - ~/.nvm/versions/node/v10.17.0/bin/node
    Yarn: 1.19.1 - /usr/bin/yarn
    npm: 6.11.3 - ~/.nvm/versions/node/v10.17.0/bin/npm
  npmPackages:
    @babel/cli: ^7.7.0 => 7.7.4 
    @babel/core: ^7.7.2 => 7.7.4 
    @babel/plugin-proposal-class-properties: ^7.7.0 => 7.7.4 
    @babel/plugin-proposal-export-default-from: ^7.5.2 => 7.7.4 
    @babel/plugin-proposal-optional-chaining: ^7.6.0 => 7.7.4 
    @babel/preset-env: ^7.7.1 => 7.7.4 
    @babel/register: ^7.7.4 => 7.7.4 
    babel-plugin-require-context-hook: ^1.0.0 => 1.0.0

Additional context/Screenshots
Run with:
mocha -r @babel/register -r test/__fixtures/chai-plugins --recursive test/unitnpx envinfo --preset babel

@babel-bot
Copy link
Collaborator

Hey @gear4s! 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."

@futagoza
Copy link

futagoza commented Nov 29, 2019

You might need to pass -r babel-plugin-require-context-hook/register to mocha when using babel-plugin-require-context-hook:

mocha -r babel-plugin-require-context-hook/register -r @babel/register -r test/__fixtures/chai-plugins --recursive test/unitnpx envinfo --preset babel

or

# test/mocha.opts
-r babel-plugin-require-context-hook/register
-r @babel/register
-r test/__fixtures/chai-plugins
--recursive
--preset babel
test/unitnpx
envinfo

# and just call
mocha

@gear4s
Copy link
Author

gear4s commented Nov 29, 2019

Thanks for replying @futagoza

I now get the error that context hook register does not exist:
ERROR: Cannot find module 'babel-plugin-require-context-hook/register'

I'm also using the test/mocha.opts

@futagoza
Copy link

Try these (just to debug, they wont let you use require.context):

  • exclude babel-plugin-require-context-hook entirely
  • other register hooks (e.g. ts-node/register)

If neither of these work, it's either a problem with mocha (most likely) or your node installation

@gear4s
Copy link
Author

gear4s commented Nov 29, 2019

I got it working, thanks for pointing out mocha and node installation

Issue was that mocha was in the global installed modules, and not part of dev dependencies. I've installed it into my project's dev deps and reinstalled node on nvm.

Thanks a lot!

@JLHwung
Copy link
Contributor

JLHwung commented Nov 29, 2019

@gear4s I am glad that your issue is resolved.

@JLHwung JLHwung closed this as completed Nov 29, 2019
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Feb 29, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: bug i: needs triage outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

4 participants