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

loader: return package format from defaultResolve if known #40980

Conversation

dygabo
Copy link
Member

@dygabo dygabo commented Nov 26, 2021

This is a proposed modification of defaultResolve to return the package
format in case it has been found during package resolution.
The format will be returned as described in the documentation:
https://nodejs.org/api/esm.html#resolvespecifier-context-defaultresolve
There is one new unit test as well:
test/es-module/test-esm-resolve-type.js

Please consider this PR as a discussion base if this feature is
correctly implemented.
The approach was to only return the format from defaultResolve if
a package.json file has been found and parsed.
All other cases only return url as before.

All unit tests are green, the new test passes as well.

The modification for recomputing the format type found in
lib/internal/modules/esm/load.js is a temporary solution for the
make test because highlight.js seems to be a dual package but
declares type: commonjs in its package.json:
https://github.com/highlightjs/highlight.js/blob/main/package.json#L35

@nodejs-github-bot nodejs-github-bot added esm Issues and PRs related to the ECMAScript Modules implementation. needs-ci PRs that need a full CI run. labels Nov 26, 2021
@aduh95
Copy link
Contributor

aduh95 commented Nov 27, 2021

@nodejs/loaders

@GeoffreyBooth
Copy link
Member

The modification for recomputing the format type found in lib/internal/modules/esm/load.js is a temporary solution for the make test because highlight.js seems to be a dual package but declares type: commonjs in its package.json

If the goal is to return the format “if known,” this edge case strikes me as a clue that perhaps the logic here is wrong or incomplete; that maybe the format isn’t actually known for certain conditions.

@dygabo
Copy link
Member Author

dygabo commented Nov 28, 2021

The modification for recomputing the format type found in lib/internal/modules/esm/load.js is a temporary solution for the make test because highlight.js seems to be a dual package but declares type: commonjs in its package.json

If the goal is to return the format “if known,” this edge case strikes me as a clue that perhaps the logic here is wrong or incomplete; that maybe the format isn’t actually known for certain conditions.

my interpretation here was that maybe the package.json of highlight.js should not define the type in its package.json since it is a dual package and commonjs is the default type in node anyway. as I am rather new to node I don't know if this conclusion is correct.

is that scenario correct from the package implementation side? removing the "type": "commonjs", line from package.json of highlight.js solves it.

for the case:
main package.json contains:

  "type": "commonjs",
[...]
  "exports": {
    ".": {
      "require": "./lib/index.js",
      "import": "./es/index.js"
    },

and es/package.json contains:

"type": "module"

is in this case the correct result "module" in case of import? If that is the case it might be that there is a bug in defaultResolve for this case even without the changes in this PR since it solves to "commonjs" (I could look into it if needed). that is not sent out and load recomputes based on path and gets to the correct "module" result.

please let me know how to proceed.

@dygabo
Copy link
Member Author

dygabo commented Nov 29, 2021

I looked a bit more into this and I think I found the part of the code where this happens:

  • getPackageConfig creates an entry in packageJSONCache including main and type that are read from the main package.json file (in the specific testcase: ./lib/index.js and commonjs respectively).
  • since the package.json contains an "export" section, packageExportsResolve gets called and this solves correctly the main script to be in the specific case ./es/index.js but it does not update the package type in the cache with the value in the ./es/package.json. In fact the code in packageExportsResolve does not look for the existence of a "deeper" package.json

I attach here a screenshot of the callstack where the script resolution happens because I think it explains more than I can do in text form:
image

if I find a feasible solution I will try to make a proposal, otherwise kindly waiting for input on this.

@aduh95
Copy link
Contributor

aduh95 commented Nov 29, 2021

my interpretation here was that maybe the package.json of highlight.js should not define the type in its package.json since it is a dual package and commonjs is the default type in node anyway. as I am rather new to node I don't know if this conclusion is correct.

The "type" field in the package.json is useful only to determine how to parse .js file. When loading a .js file, node has to look for the "closest"1 package.json to know if it has a "type" set to "module", otherwise it's parsed as CJS.

Node.js docs recommends to always set the "type" field, regardless if the package is dual or CJS-only:

node/doc/api/packages.md

Lines 80 to 84 in e31d1cb

Package authors should include the [`"type"`][] field, even in packages where
all sources are CommonJS. Being explicit about the `type` of the package will
future-proof the package in case the default type of Node.js ever changes, and
it will also make things easier for build tools and loaders to determine how the
files in the package should be interpreted.

Footnotes

  1. the one in the same directory, or one of the parent directories, which may or may not be the same package.json that defines the "exports".

@dygabo
Copy link
Member Author

dygabo commented Nov 29, 2021

The "type" field in the package.json is useful only to determine how to parse .js file. When loading a .js file, node has to look for the "closest"1 package.json to know if it has a "type" set to "module", otherwise it's parsed as CJS.

Node.js docs recommends to always set the "type" field, regardless if the package is dual or CJS-only:

node/doc/api/packages.md

Lines 80 to 84 in e31d1cb

Package authors should include the [`"type"`][] field, even in packages where
all sources are CommonJS. Being explicit about the `type` of the package will
future-proof the package in case the default type of Node.js ever changes, and
it will also make things easier for build tools and loaders to determine how the
files in the package should be interpreted.

Footnotes

  1. the one in the same directory, or one of the parent directories, which may or may not be the same package.json that defines the "exports".

Thanks for the tips. I updated the PR with one commit considering your input. I also added an additional testcase to test/es-module/test-esm-resolve-type.js to reflect the situation with the dual package and the additional package.json file.

All the tests are green and I look forward to hearing your thoughts on this.

@dygabo dygabo marked this pull request as draft November 30, 2021 08:34
@dygabo dygabo marked this pull request as ready for review November 30, 2021 08:35
Copy link
Member

@bmeck bmeck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems fine to me pending, a comment in the test case explaining what is going on regarding 2 package.json files might help though since it is rather hard to read.

@dygabo
Copy link
Member Author

dygabo commented Dec 1, 2021

Seems fine to me pending, a comment in the test case explaining what is going on regarding 2 package.json files might help though since it is rather hard to read.

I added now a comment to the source file explaining the test scenario and also check the returned url value: 022a2eb

@aduh95
Copy link
Contributor

aduh95 commented Dec 1, 2021

I'm not sure I understand this change, it looks like the added .format property is not used anywhere, so is it actually useful? Why are we adding it?

@dygabo
Copy link
Member Author

dygabo commented Dec 1, 2021

I'm not sure I understand this change, it looks like the added .format property is not used anywhere, so is it actually useful? Why are we adding it?

it actually has an effect on the behaviour of defaultLoad but more than that it might be of advantage for external loaders added with --loader to have this information in their implementation after calling the defaultResolve in the resolve hook.

@aduh95
Copy link
Contributor

aduh95 commented Dec 4, 2021

I'm not sure I understand this change, it looks like the added .format property is not used anywhere, so is it actually useful? Why are we adding it?

it actually has an effect on the behaviour of defaultLoad but more than that it might be of advantage for external loaders added with --loader to have this information in their implementation after calling the defaultResolve in the resolve hook.

Could you add a test that doesn't use --expose-internals that illustrate that? I think it would help me understand.

Copy link
Member

@JakobJingleheimer JakobJingleheimer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, thanks for this!

Custom resolve hooks can already return an optional format property, so this makes sense to me. I think there wasn't a particular reason we did not already update defaultResolve() to do this—I think maybe we were planning to do in a follow-up (so the original PR, that was already getting quite large, could land) and @dygabo got to it first 🙂

Approach and goal look good to me. Just a few hygiene nits.

lib/internal/modules/esm/resolve.js Outdated Show resolved Hide resolved
lib/internal/modules/esm/resolve.js Outdated Show resolved Hide resolved
lib/internal/modules/esm/resolve.js Outdated Show resolved Hide resolved
lib/internal/modules/esm/resolve.js Outdated Show resolved Hide resolved
lib/internal/modules/esm/resolve.js Outdated Show resolved Hide resolved
lib/internal/modules/esm/resolve.js Outdated Show resolved Hide resolved
lib/internal/modules/esm/resolve.js Outdated Show resolved Hide resolved
@dygabo
Copy link
Member Author

dygabo commented Dec 5, 2021

I'm not sure I understand this change, it looks like the added .format property is not used anywhere, so is it actually useful? Why are we adding it?

it actually has an effect on the behaviour of defaultLoad but more than that it might be of advantage for external loaders added with --loader to have this information in their implementation after calling the defaultResolve in the resolve hook.

Could you add a test that doesn't use --expose-internals that illustrate that? I think it would help me understand.

I cannot make a unit-test without the expose-internals in this case but I think it is explained by @JakobJingleheimer :
#40980 (review)

please let me know if that clarifies the use-case

@aduh95
Copy link
Contributor

aduh95 commented Dec 5, 2021

I cannot make a unit-test without the expose-internals in this case

Sure you can. For example, you could check that format and resolved are returned here:

return next(specifier, context, next);

@dygabo
Copy link
Member Author

dygabo commented Dec 5, 2021

review comments solved with: 3894a73

@dygabo
Copy link
Member Author

dygabo commented Dec 5, 2021

I cannot make a unit-test without the expose-internals in this case

Sure you can. For example, you could check that format and resolved are returned here:

return next(specifier, context, next);

thank you for the hint. If this would serve the purpose of you understanding the modification I would try to squeeze in some more tome for this next week. I thought the comment of @JakobJingleheimer explained it quite well and your question would be clarified by that.

Apart from that since I also am kind of on a tight schedule I would skip it as IMO the automated test with --experimental-loader does not bring additional value. That's because the existing testcase covers the modification as well.

Please all let me know your thoughts on this. If the additional testcase is needed I will find an evening in the upcoming week for that.

@Flarna Flarna added the request-ci Add this label to start a Jenkins CI on a PR. label Dec 6, 2021
dygabo added a commit to dynatrace-oss-contrib/node that referenced this pull request Jan 29, 2022
This is a proposed modification of defaultResolve to return the package
format in case it has been found during package resolution.
The format will be returned as described in the documentation:
https://nodejs.org/api/esm.html#resolvespecifier-context-defaultresolve
There is one new unit test as well:
test/es-module/test-esm-resolve-type.js

PR-URL: nodejs#40980
Reviewed-By: Bradley Farias <[email protected]>
Reviewed-By: Gerhard Stöbich <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
dygabo added a commit to dynatrace-oss-contrib/node that referenced this pull request Jan 29, 2022
this commit solves a regression introduced with PR-40980.
if a resolve call results in a script with .mjs extension the
is automatically set to . This avoids the case where an additional
 in the same directory as the .mjs file would declare the
 to commonjs

PR-URL: nodejs#41218
Refs: nodejs#40980
Refs: yargs/yargs#2068
Reviewed-By: Guy Bedford <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: James M Snell <[email protected]>

Backport-PR-URL: nodejs#41752
dygabo added a commit to dynatrace-oss-contrib/node that referenced this pull request Jan 31, 2022
This is a proposed modification of defaultResolve to return the package
format in case it has been found during package resolution.
The format will be returned as described in the documentation:
https://nodejs.org/api/esm.html#resolvespecifier-context-defaultresolve
There is one new unit test as well:
test/es-module/test-esm-resolve-type.js

PR-URL: nodejs#40980
Reviewed-By: Bradley Farias <[email protected]>
Reviewed-By: Gerhard Stöbich <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>

Backport-PR-URL: nodejs#41752
dygabo added a commit to dynatrace-oss-contrib/node that referenced this pull request Jan 31, 2022
this commit solves a regression introduced with PR-40980.
if a resolve call results in a script with .mjs extension the
is automatically set to . This avoids the case where an additional
 in the same directory as the .mjs file would declare the
 to commonjs

PR-URL: nodejs#41218
Refs: nodejs#40980
Refs: yargs/yargs#2068
Reviewed-By: Guy Bedford <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: James M Snell <[email protected]>

Backport-PR-URL: nodejs#41752
Linkgoron pushed a commit to Linkgoron/node that referenced this pull request Jan 31, 2022
This is a proposed modification of defaultResolve to return the package
format in case it has been found during package resolution.
The format will be returned as described in the documentation:
https://nodejs.org/api/esm.html#resolvespecifier-context-defaultresolve
There is one new unit test as well:
test/es-module/test-esm-resolve-type.js

PR-URL: nodejs#40980
Reviewed-By: Bradley Farias <[email protected]>
Reviewed-By: Gerhard Stöbich <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Linkgoron pushed a commit to Linkgoron/node that referenced this pull request Jan 31, 2022
this commit solves a regression introduced with PR-40980.
if a resolve call results in a script with .mjs extension the
is automatically set to . This avoids the case where an additional
 in the same directory as the .mjs file would declare the
 to commonjs

PR-URL: nodejs#41218
Refs: nodejs#40980
Refs: yargs/yargs#2068
Reviewed-By: Guy Bedford <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Linkgoron pushed a commit to Linkgoron/node that referenced this pull request Jan 31, 2022
Notable changes:

child_process:
  * (SEMVER-MINOR) add support for URL to `cp.fork` (Antoine du Hamel) nodejs#41225
crypto:
  * (SEMVER-MINOR) alias webcrypto.subtle and webcrypto.getRandomValues on crypto (James M Snell) nodejs#41266
doc:
  * add Mesteery to collaborators (Mestery) nodejs#41543
events:
  * (SEMVER-MINOR) graduate capturerejections to supported (James M Snell) nodejs#41267
  * (SEMVER-MINOR) add EventEmitterAsyncResource to core (James M Snell) nodejs#41246
loader:
  * (SEMVER-MINOR) return package format from defaultResolve if known (Gabriel Bota) nodejs#40980
perf_hooks:
  * (SEMVER-MINOR) multiple fixes for Histogram (James M Snell) nodejs#41153
stream:
  * (SEMVER-MINOR) add filter method to readable (Benjamin Gruenbaum, Robert Nagy) nodejs#41354
  * (SEMVER-MINOR) add isReadable helper (Robert Nagy) nodejs#41199
  * (SEMVER-MINOR) add map method to Readable (Benjamin Gruenbaum, Robert Nagy) nodejs#40815

PR-URL: nodejs#41557
danielleadams pushed a commit that referenced this pull request Jan 31, 2022
This is a proposed modification of defaultResolve to return the package
format in case it has been found during package resolution.
The format will be returned as described in the documentation:
https://nodejs.org/api/esm.html#resolvespecifier-context-defaultresolve
There is one new unit test as well:
test/es-module/test-esm-resolve-type.js

PR-URL: #40980
Reviewed-By: Bradley Farias <[email protected]>
Reviewed-By: Gerhard Stöbich <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>

Backport-PR-URL: #41752
danielleadams pushed a commit that referenced this pull request Jan 31, 2022
this commit solves a regression introduced with PR-40980.
if a resolve call results in a script with .mjs extension the
is automatically set to . This avoids the case where an additional
 in the same directory as the .mjs file would declare the
 to commonjs

PR-URL: #41218
Refs: #40980
Refs: yargs/yargs#2068
Reviewed-By: Guy Bedford <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: James M Snell <[email protected]>

Backport-PR-URL: #41752
Flarna pushed a commit to dynatrace-oss-contrib/node that referenced this pull request Jan 31, 2022
This is a proposed modification of defaultResolve to return the package
format in case it has been found during package resolution.
The format will be returned as described in the documentation:
https://nodejs.org/api/esm.html#resolvespecifier-context-defaultresolve
There is one new unit test as well:
test/es-module/test-esm-resolve-type.js

PR-URL: nodejs#40980
Reviewed-By: Bradley Farias <[email protected]>
Reviewed-By: Gerhard Stöbich <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>

Backport-PR-URL: nodejs#41752
Flarna pushed a commit to dynatrace-oss-contrib/node that referenced this pull request Jan 31, 2022
this commit solves a regression introduced with PR-40980.
if a resolve call results in a script with .mjs extension the
is automatically set to . This avoids the case where an additional
 in the same directory as the .mjs file would declare the
 to commonjs

PR-URL: nodejs#41218
Refs: nodejs#40980
Refs: yargs/yargs#2068
Reviewed-By: Guy Bedford <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: James M Snell <[email protected]>

Backport-PR-URL: nodejs#41752
danielleadams pushed a commit that referenced this pull request Feb 1, 2022
This is a proposed modification of defaultResolve to return the package
format in case it has been found during package resolution.
The format will be returned as described in the documentation:
https://nodejs.org/api/esm.html#resolvespecifier-context-defaultresolve
There is one new unit test as well:
test/es-module/test-esm-resolve-type.js

PR-URL: #40980
Reviewed-By: Bradley Farias <[email protected]>
Reviewed-By: Gerhard Stöbich <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>

Backport-PR-URL: #41752
danielleadams pushed a commit that referenced this pull request Feb 1, 2022
this commit solves a regression introduced with PR-40980.
if a resolve call results in a script with .mjs extension the
is automatically set to . This avoids the case where an additional
 in the same directory as the .mjs file would declare the
 to commonjs

PR-URL: #41218
Refs: #40980
Refs: yargs/yargs#2068
Reviewed-By: Guy Bedford <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: James M Snell <[email protected]>

Backport-PR-URL: #41752
dygabo added a commit to dynatrace-oss-contrib/node that referenced this pull request Feb 1, 2022
This is a proposed modification of defaultResolve to return the package
format in case it has been found during package resolution.
The format will be returned as described in the documentation:
https://nodejs.org/api/esm.html#resolvespecifier-context-defaultresolve
There is one new unit test as well:
test/es-module/test-esm-resolve-type.js

PR-URL: nodejs#40980
Reviewed-By: Bradley Farias <[email protected]>
Reviewed-By: Gerhard Stöbich <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>

Backport-PR-URL: nodejs#41752
dygabo added a commit to dynatrace-oss-contrib/node that referenced this pull request Feb 1, 2022
this commit solves a regression introduced with PR-40980.
if a resolve call results in a script with .mjs extension the
is automatically set to . This avoids the case where an additional
 in the same directory as the .mjs file would declare the
 to commonjs

PR-URL: nodejs#41218
Refs: nodejs#40980
Refs: yargs/yargs#2068
Reviewed-By: Guy Bedford <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: James M Snell <[email protected]>

Backport-PR-URL: nodejs#41752
danielleadams pushed a commit that referenced this pull request Feb 5, 2022
This is a proposed modification of defaultResolve to return the package
format in case it has been found during package resolution.
The format will be returned as described in the documentation:
https://nodejs.org/api/esm.html#resolvespecifier-context-defaultresolve
There is one new unit test as well:
test/es-module/test-esm-resolve-type.js

PR-URL: #40980
Reviewed-By: Bradley Farias <[email protected]>
Reviewed-By: Gerhard Stöbich <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>

Backport-PR-URL: #41752
Reviewed-By: Danielle Adams <[email protected]>
Reviewed-By: Geoffrey Booth <[email protected]>
danielleadams pushed a commit that referenced this pull request Feb 5, 2022
this commit solves a regression introduced with PR-40980.
if a resolve call results in a script with .mjs extension the
is automatically set to . This avoids the case where an additional
 in the same directory as the .mjs file would declare the
 to commonjs

PR-URL: #41218
Refs: #40980
Refs: yargs/yargs#2068
Reviewed-By: Guy Bedford <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: James M Snell <[email protected]>

Backport-PR-URL: #41752
Reviewed-By: Danielle Adams <[email protected]>
Reviewed-By: Geoffrey Booth <[email protected]>
Reviewed-By: Gerhard Stöbich <[email protected]>
danielleadams added a commit that referenced this pull request Feb 6, 2022
Notable changes:

Importing JSON modules now requires experimental import assertions syntax

This release adds experimental support for the import assertions stage 3 proposal.

To keep Node.js ESM implementation as compatible as possible with the HTML spec, import assertions
are now required to import JSON modules (still behind the `--experimental-json-modules` CLI flag):

```js
import info from './package.json' assert { type: 'json' };
// or using dynamic import:
const info = await import('./package.json', { assert: { type: 'json' } });
```

Contributed by Antoine du Hamel and Geoffrey Booth #40250

Other notable changes:

* async_hooks:
  * (SEMVER-MINOR) expose async_wrap providers (Rafael Gonzaga) #40760
* child_process:
  * (SEMVER-MINOR) add support for URL to `cp.fork` (Antoine du Hamel) #41225
* doc:
  * add @Mesteery to collaborators (Mestery) #41543
  * add @bnb as a collaborator (Tierney Cyren) #41100
* esm:
  * (SEMVER-MINOR) graduate capturerejections to supported (James M Snell) #41267
  * (SEMVER-MINOR) add EventEmitterAsyncResource to core (James M Snell) #41246
* events:
  * (SEMVER-MINOR) propagate weak option for kNewListener (James M Snell) #40899
* fs:
  * (SEMVER-MINOR) accept URL as argument for `fs.rm` and `fs.rmSync` (Antoine du Hamel) #41132
* lib:
  * (SEMVER-MINOR) make AbortSignal cloneable/transferable (James M Snell) #41050
  * (SEMVER-MINOR) add AbortSignal.timeout (James M Snell) #40899
  * (SEMVER-MINOR) add reason to AbortSignal (James M Snell) #40807
  * (SEMVER-MINOR) add unsubscribe method to non-active DC channels (simon-id) #40433
  * (SEMVER-MINOR) add return value for DC channel.unsubscribe (simon-id) #40433
* loader:
  * (SEMVER-MINOR) return package format from defaultResolve if known (Gabriel Bota) #40980
* perf_hooks:
  * (SEMVER-MINOR) multiple fixes for Histogram (James M Snell) #41153
* process:
  * (SEMVER-MINOR) add `getActiveResourcesInfo()` (Darshan Sen) #40813
* src:
  * (SEMVER-MINOR) add x509.fingerprint512 to crypto module (3nprob) #39809
  * (SEMVER-MINOR) add flags for controlling process behavior (Cheng Zhao) #40339
* stream:
  * (SEMVER-MINOR) add filter method to readable (Benjamin Gruenbaum) #41354
  * (SEMVER-MINOR) add isReadable helper (Robert Nagy) #41199
  * (SEMVER-MINOR) add map method to Readable (Benjamin Gruenbaum) #40815
  * deprecate thenable support (Antoine du Hamel) #40860
* util:
  * (SEMVER-MINOR) pass through the inspect function to custom inspect functions (Ruben Bridgewater) https://github.com/nodejs/node/pull41019
  * (SEMVER-MINOR) add numericSeparator to util.inspect (Ruben Bridgewater) #41003
  * (SEMVER-MINOR) always visualize cause property in errors during inspection (Ruben Bridgewater) https://github.com/nodejs/node/pull41002
* timers:
  * (SEMVER-MINOR) add experimental scheduler api (James M Snell) #40909
* v8:
  * (SEMVER-MINOR) multi-tenant promise hook api (Stephen Belanger) #39283

PR-URL: #41804
@danielleadams danielleadams mentioned this pull request Feb 6, 2022
danielleadams added a commit that referenced this pull request Feb 6, 2022
Notable changes:

Importing JSON modules now requires experimental import assertions syntax

This release adds experimental support for the import assertions stage 3 proposal.

To keep Node.js ESM implementation as compatible as possible with the HTML spec, import assertions
are now required to import JSON modules (still behind the `--experimental-json-modules` CLI flag):

```mjs
import info from './package.json' assert { type: 'json' };
```

Or use dynamic import:

```mjs
const info = await import('./package.json', { assert: { type: 'json' } });
```

Contributed by Antoine du Hamel and Geoffrey Booth #40250

Other notable changes:

* async_hooks:
  * (SEMVER-MINOR) expose async_wrap providers (Rafael Gonzaga) #40760
* child_process:
  * (SEMVER-MINOR) add support for URL to `cp.fork` (Antoine du Hamel) #41225
* doc:
  * add @Mesteery to collaborators (Mestery) #41543
  * add @bnb as a collaborator (Tierney Cyren) #41100
* esm:
  * (SEMVER-MINOR) graduate capturerejections to supported (James M Snell) #41267
  * (SEMVER-MINOR) add EventEmitterAsyncResource to core (James M Snell) #41246
* events:
  * (SEMVER-MINOR) propagate weak option for kNewListener (James M Snell) #40899
* fs:
  * (SEMVER-MINOR) accept URL as argument for `fs.rm` and `fs.rmSync` (Antoine du Hamel) #41132
* lib:
  * (SEMVER-MINOR) make AbortSignal cloneable/transferable (James M Snell) #41050
  * (SEMVER-MINOR) add AbortSignal.timeout (James M Snell) #40899
  * (SEMVER-MINOR) add reason to AbortSignal (James M Snell) #40807
  * (SEMVER-MINOR) add unsubscribe method to non-active DC channels (simon-id) #40433
  * (SEMVER-MINOR) add return value for DC channel.unsubscribe (simon-id) #40433
* loader:
  * (SEMVER-MINOR) return package format from defaultResolve if known (Gabriel Bota) #40980
* perf_hooks:
  * (SEMVER-MINOR) multiple fixes for Histogram (James M Snell) #41153
* process:
  * (SEMVER-MINOR) add `getActiveResourcesInfo()` (Darshan Sen) #40813
* src:
  * (SEMVER-MINOR) add x509.fingerprint512 to crypto module (3nprob) #39809
  * (SEMVER-MINOR) add flags for controlling process behavior (Cheng Zhao) #40339
* stream:
  * (SEMVER-MINOR) add filter method to readable (Benjamin Gruenbaum) #41354
  * (SEMVER-MINOR) add isReadable helper (Robert Nagy) #41199
  * (SEMVER-MINOR) add map method to Readable (Benjamin Gruenbaum) #40815
  * deprecate thenable support (Antoine du Hamel) #40860
* util:
  * (SEMVER-MINOR) pass through the inspect function to custom inspect functions (Ruben Bridgewater) https://github.com/nodejs/node/pull41019
  * (SEMVER-MINOR) add numericSeparator to util.inspect (Ruben Bridgewater) #41003
  * (SEMVER-MINOR) always visualize cause property in errors during inspection (Ruben Bridgewater) https://github.com/nodejs/node/pull41002
* timers:
  * (SEMVER-MINOR) add experimental scheduler api (James M Snell) #40909
* v8:
  * (SEMVER-MINOR) multi-tenant promise hook api (Stephen Belanger) #39283

PR-URL: #41804
danielleadams added a commit that referenced this pull request Feb 6, 2022
Notable changes:

Importing JSON modules now requires experimental import assertions syntax

This release adds experimental support for the import assertions stage 3 proposal.

To keep Node.js ESM implementation as compatible as possible with the HTML spec, import assertions
are now required to import JSON modules (still behind the `--experimental-json-modules` CLI flag):

```mjs
import info from './package.json' assert { type: 'json' };
```

Or use dynamic import:

```mjs
const info = await import('./package.json', { assert: { type: 'json' } });
```

Contributed by Antoine du Hamel and Geoffrey Booth #40250

Other notable changes:

* async_hooks:
  * (SEMVER-MINOR) expose async_wrap providers (Rafael Gonzaga) #40760
* child_process:
  * (SEMVER-MINOR) add support for URL to `cp.fork` (Antoine du Hamel) #41225
* doc:
  * add @Mesteery to collaborators (Mestery) #41543
  * add @bnb as a collaborator (Tierney Cyren) #41100
* esm:
  * (SEMVER-MINOR) graduate capturerejections to supported (James M Snell) #41267
  * (SEMVER-MINOR) add EventEmitterAsyncResource to core (James M Snell) #41246
* events:
  * (SEMVER-MINOR) propagate weak option for kNewListener (James M Snell) #40899
* fs:
  * (SEMVER-MINOR) accept URL as argument for `fs.rm` and `fs.rmSync` (Antoine du Hamel) #41132
* lib:
  * (SEMVER-MINOR) make AbortSignal cloneable/transferable (James M Snell) #41050
  * (SEMVER-MINOR) add AbortSignal.timeout (James M Snell) #40899
  * (SEMVER-MINOR) add reason to AbortSignal (James M Snell) #40807
  * (SEMVER-MINOR) add unsubscribe method to non-active DC channels (simon-id) #40433
  * (SEMVER-MINOR) add return value for DC channel.unsubscribe (simon-id) #40433
* loader:
  * (SEMVER-MINOR) return package format from defaultResolve if known (Gabriel Bota) #40980
* perf_hooks:
  * (SEMVER-MINOR) multiple fixes for Histogram (James M Snell) #41153
* process:
  * (SEMVER-MINOR) add `getActiveResourcesInfo()` (Darshan Sen) #40813
* src:
  * (SEMVER-MINOR) add x509.fingerprint512 to crypto module (3nprob) #39809
  * (SEMVER-MINOR) add flags for controlling process behavior (Cheng Zhao) #40339
* stream:
  * (SEMVER-MINOR) add filter method to readable (Benjamin Gruenbaum) #41354
  * (SEMVER-MINOR) add isReadable helper (Robert Nagy) #41199
  * (SEMVER-MINOR) add map method to Readable (Benjamin Gruenbaum) #40815
  * deprecate thenable support (Antoine du Hamel) #40860
* util:
  * (SEMVER-MINOR) pass through the inspect function to custom inspect functions (Ruben Bridgewater) #41019
  * (SEMVER-MINOR) add numericSeparator to util.inspect (Ruben Bridgewater) #41003
  * (SEMVER-MINOR) always visualize cause property in errors during inspection (Ruben Bridgewater) #41002
* timers:
  * (SEMVER-MINOR) add experimental scheduler api (James M Snell) #40909
* v8:
  * (SEMVER-MINOR) multi-tenant promise hook api (Stephen Belanger) #39283

PR-URL: #41804
danielleadams added a commit that referenced this pull request Feb 6, 2022
Notable changes:

Importing JSON modules now requires experimental import assertions
syntax

This release adds experimental support for the import assertions stage 3
proposal.

To keep Node.js ESM implementation as compatible as possible with the
HTML spec, import assertions are now required to import JSON modules
(still behind the `--experimental-json-modules` CLI flag):

```mjs
import info from './package.json' assert { type: 'json' };
```

Or use dynamic import:

```mjs
const info = await import('./package.json', {
  assert: { type: 'json' }
});
```

Contributed by Antoine du Hamel and Geoffrey Booth #40250

Other notable changes:

* async_hooks:
  * (SEMVER-MINOR) expose async_wrap providers (Rafael Gonzaga) #40760
* child_process:
  * (SEMVER-MINOR) add support for URL to `cp.fork` (Antoine du Hamel) #41225
* doc:
  * add @Mesteery to collaborators (Mestery) #41543
  * add @bnb as a collaborator (Tierney Cyren) #41100
* esm:
  * (SEMVER-MINOR) graduate capturerejections to supported (James M Snell) #41267
  * (SEMVER-MINOR) add EventEmitterAsyncResource to core (James M Snell) #41246
* events:
  * (SEMVER-MINOR) propagate weak option for kNewListener (James M Snell) #40899
* fs:
  * (SEMVER-MINOR) accept URL as argument for `fs.rm` and `fs.rmSync` (Antoine du Hamel) #41132
* lib:
  * (SEMVER-MINOR) make AbortSignal cloneable/transferable (James M Snell) #41050
  * (SEMVER-MINOR) add AbortSignal.timeout (James M Snell) #40899
  * (SEMVER-MINOR) add reason to AbortSignal (James M Snell) #40807
  * (SEMVER-MINOR) add unsubscribe method to non-active DC channels (simon-id) #40433
  * (SEMVER-MINOR) add return value for DC channel.unsubscribe (simon-id) #40433
* loader:
  * (SEMVER-MINOR) return package format from defaultResolve if known (Gabriel Bota) #40980
* perf_hooks:
  * (SEMVER-MINOR) multiple fixes for Histogram (James M Snell) #41153
* process:
  * (SEMVER-MINOR) add `getActiveResourcesInfo()` (Darshan Sen) #40813
* src:
  * (SEMVER-MINOR) add x509.fingerprint512 to crypto module (3nprob) #39809
  * (SEMVER-MINOR) add flags for controlling process behavior (Cheng Zhao) #40339
* stream:
  * (SEMVER-MINOR) add filter method to readable (Benjamin Gruenbaum) #41354
  * (SEMVER-MINOR) add isReadable helper (Robert Nagy) #41199
  * (SEMVER-MINOR) add map method to Readable (Benjamin Gruenbaum) #40815
  * deprecate thenable support (Antoine du Hamel) #40860
* util:
  * (SEMVER-MINOR) pass through the inspect function to custom inspect functions (Ruben Bridgewater) #41019
  * (SEMVER-MINOR) add numericSeparator to util.inspect (Ruben Bridgewater) #41003
  * (SEMVER-MINOR) always visualize cause property in errors during inspection (Ruben Bridgewater) #41002
* timers:
  * (SEMVER-MINOR) add experimental scheduler api (James M Snell) #40909
* v8:
  * (SEMVER-MINOR) multi-tenant promise hook api (Stephen Belanger) #39283

PR-URL: #41804
danielleadams added a commit that referenced this pull request Feb 7, 2022
Notable changes:

Importing JSON modules now requires experimental import assertions
syntax

This release adds experimental support for the import assertions stage 3
proposal.

To keep Node.js ESM implementation as compatible as possible with the
HTML spec, import assertions are now required to import JSON modules
(still behind the `--experimental-json-modules` CLI flag):

```mjs
import info from './package.json' assert { type: 'json' };
```

Or use dynamic import:

```mjs
const info = await import('./package.json', {
  assert: { type: 'json' }
});
```

Contributed by Antoine du Hamel and Geoffrey Booth #40250

Other notable changes:

* async_hooks:
  * (SEMVER-MINOR) expose async_wrap providers (Rafael Gonzaga) #40760
* child_process:
  * (SEMVER-MINOR) add support for URL to `cp.fork` (Antoine du Hamel) #41225
* doc:
  * add @Mesteery to collaborators (Mestery) #41543
  * add @bnb as a collaborator (Tierney Cyren) #41100
* esm:
  * (SEMVER-MINOR) graduate capturerejections to supported (James M Snell) #41267
  * (SEMVER-MINOR) add EventEmitterAsyncResource to core (James M Snell) #41246
* events:
  * (SEMVER-MINOR) propagate weak option for kNewListener (James M Snell) #40899
* fs:
  * (SEMVER-MINOR) accept URL as argument for `fs.rm` and `fs.rmSync` (Antoine du Hamel) #41132
* lib:
  * (SEMVER-MINOR) make AbortSignal cloneable/transferable (James M Snell) #41050
  * (SEMVER-MINOR) add AbortSignal.timeout (James M Snell) #40899
  * (SEMVER-MINOR) add reason to AbortSignal (James M Snell) #40807
  * (SEMVER-MINOR) add unsubscribe method to non-active DC channels (simon-id) #40433
  * (SEMVER-MINOR) add return value for DC channel.unsubscribe (simon-id) #40433
* loader:
  * (SEMVER-MINOR) return package format from defaultResolve if known (Gabriel Bota) #40980
* perf_hooks:
  * (SEMVER-MINOR) multiple fixes for Histogram (James M Snell) #41153
* process:
  * (SEMVER-MINOR) add `getActiveResourcesInfo()` (Darshan Sen) #40813
* src:
  * (SEMVER-MINOR) add x509.fingerprint512 to crypto module (3nprob) #39809
  * (SEMVER-MINOR) add flags for controlling process behavior (Cheng Zhao) #40339
* stream:
  * (SEMVER-MINOR) add filter method to readable (Benjamin Gruenbaum) #41354
  * (SEMVER-MINOR) add isReadable helper (Robert Nagy) #41199
  * (SEMVER-MINOR) add map method to Readable (Benjamin Gruenbaum) #40815
  * deprecate thenable support (Antoine du Hamel) #40860
* util:
  * (SEMVER-MINOR) pass through the inspect function to custom inspect functions (Ruben Bridgewater) #41019
  * (SEMVER-MINOR) add numericSeparator to util.inspect (Ruben Bridgewater) #41003
  * (SEMVER-MINOR) always visualize cause property in errors during inspection (Ruben Bridgewater) #41002
* timers:
  * (SEMVER-MINOR) add experimental scheduler api (James M Snell) #40909
* v8:
  * (SEMVER-MINOR) multi-tenant promise hook api (Stephen Belanger) #39283

PR-URL: #41804
danielleadams added a commit that referenced this pull request Feb 8, 2022
Notable changes:

Importing JSON modules now requires experimental import assertions
syntax

This release adds experimental support for the import assertions stage 3
proposal.

To keep Node.js ESM implementation as compatible as possible with the
HTML spec, import assertions are now required to import JSON modules
(still behind the `--experimental-json-modules` CLI flag):

```mjs
import info from './package.json' assert { type: 'json' };
```

Or use dynamic import:

```mjs
const info = await import('./package.json', {
  assert: { type: 'json' }
});
```

Contributed by Antoine du Hamel and Geoffrey Booth #40250

Other notable changes:

* async_hooks:
  * (SEMVER-MINOR) expose async_wrap providers (Rafael Gonzaga) #40760
* child_process:
  * (SEMVER-MINOR) add support for URL to `cp.fork` (Antoine du Hamel) #41225
* doc:
  * add @Mesteery to collaborators (Mestery) #41543
  * add @bnb as a collaborator (Tierney Cyren) #41100
* esm:
  * (SEMVER-MINOR) graduate capturerejections to supported (James M Snell) #41267
  * (SEMVER-MINOR) add EventEmitterAsyncResource to core (James M Snell) #41246
* events:
  * (SEMVER-MINOR) propagate weak option for kNewListener (James M Snell) #40899
* fs:
  * (SEMVER-MINOR) accept URL as argument for `fs.rm` and `fs.rmSync` (Antoine du Hamel) #41132
* lib:
  * (SEMVER-MINOR) make AbortSignal cloneable/transferable (James M Snell) #41050
  * (SEMVER-MINOR) add AbortSignal.timeout (James M Snell) #40899
  * (SEMVER-MINOR) add reason to AbortSignal (James M Snell) #40807
  * (SEMVER-MINOR) add unsubscribe method to non-active DC channels (simon-id) #40433
  * (SEMVER-MINOR) add return value for DC channel.unsubscribe (simon-id) #40433
* loader:
  * (SEMVER-MINOR) return package format from defaultResolve if known (Gabriel Bota) #40980
* perf_hooks:
  * (SEMVER-MINOR) multiple fixes for Histogram (James M Snell) #41153
* process:
  * (SEMVER-MINOR) add `getActiveResourcesInfo()` (Darshan Sen) #40813
* src:
  * (SEMVER-MINOR) add x509.fingerprint512 to crypto module (3nprob) #39809
  * (SEMVER-MINOR) add flags for controlling process behavior (Cheng Zhao) #40339
* stream:
  * (SEMVER-MINOR) add filter method to readable (Benjamin Gruenbaum) #41354
  * (SEMVER-MINOR) add isReadable helper (Robert Nagy) #41199
  * (SEMVER-MINOR) add map method to Readable (Benjamin Gruenbaum) #40815
  * deprecate thenable support (Antoine du Hamel) #40860
* util:
  * (SEMVER-MINOR) pass through the inspect function to custom inspect functions (Ruben Bridgewater) #41019
  * (SEMVER-MINOR) add numericSeparator to util.inspect (Ruben Bridgewater) #41003
  * (SEMVER-MINOR) always visualize cause property in errors during inspection (Ruben Bridgewater) #41002
* timers:
  * (SEMVER-MINOR) add experimental scheduler api (James M Snell) #40909
* v8:
  * (SEMVER-MINOR) multi-tenant promise hook api (Stephen Belanger) #39283

PR-URL: #41804
nginx-hg-mirror pushed a commit to nginx/unit that referenced this pull request Jun 2, 2022
Before Node.js v16.14.0 the "format" value in defaultResolve
was ignored so error was hidden.  For more information see:
nodejs/node#40980
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
esm Issues and PRs related to the ECMAScript Modules implementation. loaders Issues and PRs related to ES module loaders semver-minor PRs that contain new features and should be released in the next minor version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants