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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Usage of node: imports for builtin modules #11637

Closed
theoludwig opened this issue Jul 3, 2021 · 2 comments
Closed

[Bug] Usage of node: imports for builtin modules #11637

theoludwig opened this issue Jul 3, 2021 · 2 comments

Comments

@theoludwig
Copy link
Contributor

馃悰 Bug Report

With the arrival of Node.js v16, we can now use node: to load Node.js builtin modules with require.
See: https://nodejs.org/api/esm.html#esm_node_imports

But currently with jest, we can't, it fails.

To Reproduce

Steps to reproduce the behavior (it is a stupid example, only to show the error):

In a file lib.js :

const path = require('node:path')

const getPath = (string) => {
  return path.resolve(string)
}

module.exports = getPath

And a file lib.test.js :

const getPath = require('./lib.js')

test('getPath', () => {
  expect(getPath('./app').endsWith('/app')).toBeTruthy()
})

image

Expected behavior

To make it work again, I need to change const path = require('node:path') to const path = require('path').

image

Problematic code

https://github.com/facebook/jest/blob/7a64ede2163eba4ecc725f448cd92102cd8c14aa/packages/jest-runtime/src/index.ts#L1909-L1919

envinfo

  System:
    OS: Linux 5.8 Ubuntu 20.04.2 LTS (Focal Fossa)
    CPU: (4) x64 Intel(R) Core(TM) i5-4690K CPU @ 3.50GHz
  Binaries:
    Node: 16.4.0 - ~/.nvm/versions/node/v16.4.0/bin/node
    npm: 7.19.1 - ~/Documents/Thream/api/node_modules/.bin/npm
  npmPackages:
    jest: 27.0.6 => 27.0.6 
chadoh added a commit to near/near-workspaces-js that referenced this issue Aug 18, 2021
XO is a wrapper around eslint: https://github.com/xojs/xo

* add precommit hooks with husky
* drop support for node 15

Needed to override `node:` import prefix because it is incompatible with Jest (jestjs/jest#11637)
@SimenB
Copy link
Member

SimenB commented Aug 27, 2021

#11331

@SimenB SimenB closed this as completed Aug 27, 2021
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants