-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
export * from 'dependency' not working when { "type": "module" } #32613
Comments
@marcofranssen do you still have the same problem if you stop using the We are aiming to unflag ESM in 12.x in 12.17.0 which is scheduled to come out May 26th |
@MylesBorins Do you mean by |
@marcofranssen the flag is currently requried but we plan to remove the need for the flag in 12.17.0 |
That results in the following when loading for example a package.json via import. node:22538) ExperimentalWarning: The ESM module loader is experimental.
internal/modules/run_main.js:57
internalBinding('errors').triggerUncaughtException(
^
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".json" for /Users/marco/code/my-project/package.json
at Loader.defaultGetFormat [as _getFormat] (internal/modules/esm/get_format.js:71:15)
at Loader.resolve (internal/modules/esm/loader.js:98:42)
at async Loader.getModuleJob (internal/modules/esm/loader.js:188:29)
at async ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:44:17) {
code: 'ERR_UNKNOWN_FILE_EXTENSION'
} See here an example of what I'm using. #!/bin/sh
':' //# http://sambal.org/?p=1014 ; exec /usr/bin/env node --experimental-modules "$0" "$@"
'use strict'
import program from 'commander'
import pkg from '../package.json'
program
.version(pkg.version)
.description(pkg.description)
.parse(process.argv) When using with esm like this it works just fine as long my package.json doesn't include #!/bin/sh
':' //# http://sambal.org/?p=1014 ; exec /usr/bin/env node -r esm "$0" "$@"
import program from 'commander'
import pkg from '../package.json'
program
.version(pkg.version)
.description(pkg.description)
.parse(process.argv) we run this app via my-project/bin/my-proj |
@marcofranssen our loader does not support loading JSON by default. It is an experimental feature which can be enabled with |
Another possibility is to make your own require function inside of your module and use that to require JSON import { createRequire } from 'module';
const require = createRequire(import.meta.url);
const pkg = require('./package.json'); |
I'm going to close this issue as there isn't a problem in Node.js core. Please feel free to continue the discussion though |
@MylesBorins when will the experimental-json-modules become default? Also in 12.17.0? |
The current experimental json modules are unlikely to be unflagged. We are
working at tc39 to try and find a way for ESM json modules to be
implemented that could be supported by both node and the browser.
The current implantation could not work for browsers due to security
concerns.
The module attributes proposal is currently the best chance we have at a
standard way to.load json modules
…On Tue, Apr 14, 2020, 7:38 AM Marco Franssen ***@***.***> wrote:
@MylesBorins <https://github.com/MylesBorins> when will the
experimental-json-modules become default? Also in 12.17.0?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#32613 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AADZYVYW3PQF4ZFZ5U7OVWTRMRDMLANCNFSM4L2DZ55A>
.
|
Node Version: v12.16.1
dependency
esm
version: 3.2.25When
"type": "module"
is defined inpackage.json
the following is not allowed in a file.It gives the following error.
I would expect this code to completely valid.
The idea to define type module is to be able to use the node 13 feature out of the box when on node 13 and use
esm
in node 12.Is this a bug or missing feature in the implementation? Or is it me doing something I'm not supposed to do?
The text was updated successfully, but these errors were encountered: