Repository navigation
import does not work correctly #31120
Copy link
Copy link
Closed
Labels
esmIssues and PRs related to the ECMAScript Modules implementation.Issues and PRs related to the ECMAScript Modules implementation.experimentalIssues and PRs related to experimental features.Issues and PRs related to experimental features.
Description
node v13.2.0
examples
import { createAdapter, map, runEffect, now } from 'https://unpkg.com/@direktspeed/stream@0.0.17/core.mjs'
/*
node stream-web-element.mjs
(node:739700) ExperimentalWarning: The ESM module loader is experimental.
internal/modules/esm/default_resolve.js:94
let url = moduleWrapResolve(specifier, parentURL);
^
Error: Cannot find module /@direktspeed/stream@0.0.17/core.mjs imported from /home/frank//es-streams/docs/stream-web-element.mjs
at Loader.resolve [as _resolve] (internal/modules/esm/default_resolve.js:94:13)
at Loader.resolve (internal/modules/esm/loader.js:74:33)
at Loader.getModuleJob (internal/modules/esm/loader.js:148:40)
at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:41:40)
at link (internal/modules/esm/module_job.js:40:36) {
code: 'ERR_MODULE_NOT_FOUND'
}
*/dynamic also but diffrent error
import('https://unpkg.com/@direktspeed/stream@0.0.17/core.mjs')
.then(({ createAdapter, map, runEffect, now }) => {}).catch(console.log)
/*
node stream-web-element.mjs
(node:739810) ExperimentalWarning: The ESM module loader is experimental.
Error: Cannot find module /@direktspeed/stream@0.0.17/core.mjs imported from /home/frank/es-streams/docs/stream-web-element.mjs
at Loader.resolve [as _resolve] (internal/modules/esm/default_resolve.js:94:13)
at Loader.resolve (internal/modules/esm/loader.js:74:33)
at Loader.getModuleJob (internal/modules/esm/loader.js:148:40)
at Loader.import (internal/modules/esm/loader.js:132:28)
at importModuleDynamically (internal/modules/esm/translators.js:76:36)
at exports.importModuleDynamicallyCallback (internal/process/esm_loader.js:31:14)
at file:///home/frank/docker/apps/stealify/es-streams/docs/stream-web-element.mjs:12:1
at ModuleJob.run (internal/modules/esm/module_job.js:109:37)
at async Loader.import (internal/modules/esm/loader.js:133:24) {
code: 'ERR_MODULE_NOT_FOUND'
}
*/it looks like he stripps the http domain part and only uses path maybe i need to define a base url or what happens there?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
esmIssues and PRs related to the ECMAScript Modules implementation.Issues and PRs related to the ECMAScript Modules implementation.experimentalIssues and PRs related to experimental features.Issues and PRs related to experimental features.
Activity
frank-dspeed commentedon Dec 28, 2019
maybe related nodejs/modules#458
ljharb commentedon Dec 28, 2019
cc @nodejs/modules-active-members
MylesBorins commentedon Dec 28, 2019
Node's esm loader does not support loading from http(s) urls currently.
We likely could offer a better error message though.
devsnek commentedon Dec 28, 2019
it appears that it was turned into a file path without verifying that the scheme was
file:. we should definitely fix that.frank-dspeed commentedon Dec 29, 2019
Wow ok so i will need a special import helper that does fetch eval thanks for pointing that out.
frank-dspeed commentedon Dec 29, 2019
can some one point me to a similar code example that implaments import?
GeoffreyBooth commentedon Dec 29, 2019
If you're looking to use
importto pull in an HTTP URL into an ES module context, that's not possible at present. #30986 would allow for you to use a loader to do so, and there's an example of an HTTP loader in that PR.frank-dspeed commentedon Dec 29, 2019
can be closed i have writen the universal loader of my dreams :)
frank-dspeed commentedon Dec 29, 2019
@GeoffreyBooth
This is my loader Implamentation that accepts strings and exports them as ESM Module without eval :)