Node: esm: Bug in dynamic modules refactoring

Created on 14 Jan 2019  路  7Comments  路  Source: nodejs/node

Reposted from https://github.com/nodejs/help/issues/1717.

Specs:

  • Node.js Version:

    • Tested and working:

    • v11.3.0

    • Tested and broken:

    • v11.4.0

    • v11.5.0

  • OS: Tested on Linux Mint 19.1 Cinnamon

    • Linux HOSTNAME 4.15.0-43-generic #46-Ubuntu SMP Thu Dec 6 14:45:28 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

  • Scope (install, code, runtime, meta, other?): ES6 Module Import Regression from v11.3.0 to v11.4.0 using --experimental-modules
  • Module (and version) (if relevant): request-promise-native, but stacktrace also points to psl and core node as suspect.

Problem Statement:

Importing request-promise-native using ES6 module syntax on v11.4.0 or v11.5.0 causes a stacktrace which (I think) points to an error in core node:

kevin@rayquaza:~/tmp$ node --experimental-modules index.mjs 
(node:13310) ExperimentalWarning: The ESM module loader is experimental.
TypeError: Cannot read property 'onReady' of undefined
    at Module.load (internal/modules/cjs/loader.js:631:22)
    at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
    at Function.Module._load (internal/modules/cjs/loader.js:552:3)
    at Module.require (internal/modules/cjs/loader.js:659:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Object.<anonymous> (/home/kevin/tmp/node_modules/psl/index.js:14:19)
    at Module._compile (internal/modules/cjs/loader.js:723:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:734:10)
    at Module.load (internal/modules/cjs/loader.js:620:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:560:12)

Steps To Reproduce:

  • Be on node version v11.4.0 or later:

    • nvm install v11.4.0

  • Clone (or otherwise duplicate) the project from this gist: https://gist.github.com/kj800x/f08f44305429bbf8fdd65f9991cb2a71

    • git clone https://gist.github.com/kj800x/f08f44305429bbf8fdd65f9991cb2a71 && cd f08f44305429bbf8fdd65f9991cb2a71

    • It consists of an index file that imports request-promise-native and a package.json and a package-lock.json

  • Install dependencies:

    • npm i

  • Run the code

    • npm start

    • ACTUAL: Observe the stacktrace and error

  • Switch to node version v11.3.0

    • nvm install v11.3.0

  • Run the code

    • npm start

    • EXPECTED: Observe that you are able to successfully import the module without errors.

Related

The last three comments on this request-promise-native issue are related: https://github.com/request/request-promise-native/issues/1#issuecomment-450769515

confirmed-bug

Most helpful comment

This issue is also happening in the 10 LTS version, breaking in 10.15.3. See #26595.

All 7 comments

This issue is also happening in the 10 LTS version, breaking in 10.15.3. See #26595.

I can confirm, we got the same error when trying to update from 10.15.1 to 10.15.3.

This also triggers the bug (Node.js v10.15.2 ok, v10.15.3 buggy):

import blockchainWalletService from 'blockchain-wallet-service'

See https://github.com/nodejs/node/issues/25310#issuecomment-474225219.

Was hoping there would be some progress with 12.x release. Are there any plans to fix it in the near future?

I am able to reproduce the bug, I think I am able to isolate it: https://github.com/nodejs/node/pull/27443/files

Steps to reproduce:
Execute the file with the --experimental-modules flag => crashes
Execute the file without the --experimental-modules flag => works fine

Unfortunately I didn't find a successful fix, I feel I don't have enough experience on the CJS loader to understand the bug. I am leaving my test available for anyone who wants to work on that.

This issue is also happening in the 12.2.0 version.

This issue is also happening in the 12.2.0 version.

Also happening in the 12.1.0 version.

Was this page helpful?
0 / 5 - 0 ratings