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

import does not work correctly #31120

Closed
frank-dspeed opened this issue Dec 28, 2019 · 9 comments
Closed

import does not work correctly #31120

frank-dspeed opened this issue Dec 28, 2019 · 9 comments
Labels
esm Issues and PRs related to the ECMAScript Modules implementation. experimental Issues and PRs related to experimental features.

Comments

@frank-dspeed
Copy link
Contributor

frank-dspeed commented Dec 28, 2019

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?

@frank-dspeed
Copy link
Contributor Author

maybe related nodejs/modules#458

@ljharb
Copy link
Member

ljharb commented Dec 28, 2019

cc @nodejs/modules-active-members

@MylesBorins
Copy link
Member

Node's esm loader does not support loading from http(s) urls currently.

We likely could offer a better error message though.

@devsnek devsnek added esm Issues and PRs related to the ECMAScript Modules implementation. experimental Issues and PRs related to experimental features. labels Dec 28, 2019
@devsnek
Copy link
Member

devsnek commented 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
Copy link
Contributor Author

Wow ok so i will need a special import helper that does fetch eval thanks for pointing that out.

@frank-dspeed
Copy link
Contributor Author

can some one point me to a similar code example that implaments import?

var m = require('module')
var src = 'module.exports = 42'
var res = require('vm').runInThisContext(m.wrap(src))(exports, require, module, __filename, __dirname)
console.log(module.exports)

@GeoffreyBooth
Copy link
Member

If you're looking to use import to 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
Copy link
Contributor Author

can be closed i have writen the universal loader of my dreams :)

@frank-dspeed
Copy link
Contributor Author

frank-dspeed commented Dec 29, 2019

@GeoffreyBooth
This is my loader Implamentation that accepts strings and exports them as ESM Module without eval :)

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. experimental Issues and PRs related to experimental features.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants