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

Fail to load request-promise-native with --experimental-modules #25310

Closed
badeball opened this issue Jan 2, 2019 · 7 comments
Closed

Fail to load request-promise-native with --experimental-modules #25310

badeball opened this issue Jan 2, 2019 · 7 comments
Labels
esm Issues and PRs related to the ECMAScript Modules implementation.

Comments

@badeball
Copy link

badeball commented Jan 2, 2019

Hi,

I've been using experimental modules for some time now, but encountered an issue with node-11.4 in combination with request-promise-native. The mentioned module is using stealthy-request to do something clever.

Below is an example command that illustrates the problem by throwing an error in node-11.{4,5,6}, but exits successfully in node-11.3.

docker run \
  node:11.4-alpine \
  sh -c " \
    npm install request request-promise-native && \
    node \
    --experimental-modules \
    --no-warnings \
    --require request-promise-native"

I attempted to bisect the source and found 1743568 from #24560 to have introduced the change in behavior (@MylesBorins).

I'm not sure if this is an issue with node or if stealthy-require is doing something it shouldn't, but I figured I should mentioned it anyway.

The error thrown:

internal/modules/cjs/loader.js:631
      module.reflect.onReady((reflect) => {
                     ^

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> (/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)
@Trott Trott added the esm Issues and PRs related to the ECMAScript Modules implementation. label Jan 2, 2019
@Trott
Copy link
Member

Trott commented Jan 2, 2019

/ping @nodejs/modules

Standard disclaimer: Since modules are experimental, breaking changes can happen at any time, so this might just be one of those things where you (or in this case, perhaps one of the modules in your dependencies) use something that's explicitly unstable and stuff breaks on you unexpectedly.

@aledalgrande
Copy link

aledalgrande commented Feb 10, 2019

same on Mac Mohave and node 11.9.0, rolling back to 11.3.0 fixed it

@devsnek
Copy link
Member

devsnek commented Feb 10, 2019

I finally figured out the logic of why cjs to esm is always broken... should hopefully have a fix in the next few days.

@jaydenseric
Copy link
Contributor

When attempting:

import blockchainWalletService from 'blockchain-wallet-service'

I'm getting:

TypeError: Cannot read property 'onReady' of undefined
    at Module.load (internal/modules/cjs/loader.js:611:22)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
    at Function.Module._load (internal/modules/cjs/loader.js:531:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Object.<anonymous> ([redacted]/node_modules/request/lib/helpers.js:5:14)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
    at Function.Module._load (internal/modules/cjs/loader.js:531:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Object.<anonymous> ([redacted]/node_modules/request/index.js:19:15)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)

It works fine when using require without --experimental-modules:

const blockchainWalletService = require('blockchain-wallet-service')

Node.js v10.15.3

@jaydenseric
Copy link
Contributor

Duplicate: #25482

@maxnordlund
Copy link

I encountered this as well, and solved it using the following hack:

// Disable stealthy-require as it breaks ESM in modernish node

// 1. Load stealthy-require into the require cache. This way all the module
//    machinery gets run like normal.
require("stealthy-require")

// 1. Overwrite the real function with a dummy one
require.cache[require.resolve("stealthy-require")].exports = notSoSthealthyRequire

// 3. Dummy implementation that calls the provided callbacks in the right order
//    but doesn't do anything fancy to the require cache.
function notSoSthealthyRequire(_requireCache, callback, callbackForModulesToKeep, _module) {
  callbackForModulesToKeep()
  return callback()
}

@targos
Copy link
Member

targos commented Jul 21, 2019

This seems to be fixed in latest v12.x

@targos targos closed this as completed Jul 21, 2019
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.
Projects
None yet
Development

No branches or pull requests

7 participants