Skip to content

import does not work correctly #31120

Closed
Closed

Description

@frank-dspeed

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?

Activity

  1. frank-dspeed commented on Dec 28, 2019

    @frank-dspeed
    ContributorAuthor

    maybe related nodejs/modules#458

  2. ljharb commented on Dec 28, 2019

    @ljharb
    SponsorMember

    cc @nodejs/modules-active-members

  3. MylesBorins commented on Dec 28, 2019

    @MylesBorins
    Contributor

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

    We likely could offer a better error message though.

  4. added
    esmIssues and PRs related to the ECMAScript Modules implementation.
    experimentalIssues and PRs related to experimental features.
    on Dec 28, 2019
  5. devsnek commented on Dec 28, 2019

    @devsnek
    Member

    it appears that it was turned into a file path without verifying that the scheme was file:. we should definitely fix that.

  6. frank-dspeed commented on Dec 29, 2019

    @frank-dspeed
    ContributorAuthor

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

  7. frank-dspeed commented on Dec 29, 2019

    @frank-dspeed
    ContributorAuthor

    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)
  8. GeoffreyBooth commented on Dec 29, 2019

    @GeoffreyBooth
    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.

  9. frank-dspeed commented on Dec 29, 2019

    @frank-dspeed
    ContributorAuthor

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

  10. frank-dspeed commented on Dec 29, 2019

    @frank-dspeed
    ContributorAuthor

    @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

Metadata

Metadata

Assignees

No one assigned

    Labels

    esmIssues and PRs related to the ECMAScript Modules implementation.experimentalIssues and PRs related to experimental features.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions