Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

error [ERR_REQUIRE_ESM] with esm/cjs hybrid module and non-hybrid cjs dependency #286

Closed
dnalborczyk opened this issue Feb 19, 2018 · 8 comments
Labels

Comments

@dnalborczyk
Copy link
Contributor

dnalborczyk commented Feb 19, 2018

graphql recently published a new version 0.13.1 with ESM .mjs support in addition to CJS graphql/graphql-js#1244

every CJS module having a dependency on graphql is throwing an error now when loaded with std/esm.

node.js: 9.5.0
std/esm: 0.22.0 (also tried a variety of previous versions to see if it is a regression)

repro:

index.js

// hybrid module
import { execute, subscribe } from 'graphql'
// cjs module (has an internal dependency on graphql)
import apolloServerHapi from 'apollo-server-hapi'

esmrc

{
  "esm": "js",
  "cache": false
}

console

npm install @std/esm graphql apollo-server-hapi

node -r @std/esm index.js

error:

/std-esm-module-test/node_modules/graphql/index.js:1
Error [ERR_REQUIRE_ESM]: Must opt-in @std/esm@0.22.0 to load ES Module: file:///std-esm-module-test/node_modules/graphql/graphql.mjs
    at Function.module.exports.$._load (/std-esm-module-test/node_modules/@std/esm/esm.js:1)
    at $.module.exports.$.require (/std-esm-module-test/node_modules/@std/esm/esm.js:1)
    at $.t (/std-esm-module-test/node_modules/@std/esm/esm.js:1)
    at v (/std-esm-module-test/node_modules/@std/esm/esm.js:1)
    at Object.<anonymous> (/std-esm-module-test/node_modules/graphql/index.js:7:16)
    at Object.module.exports.t.a [as call] (/std-esm-module-test/node_modules/@std/esm/esm.js:1)
    at j (/std-esm-module-test/node_modules/@std/esm/esm.js:1)
    at Object.run (/std-esm-module-test/node_modules/@std/esm/esm.js:1)
    at Object.<anonymous> (/std-esm-module-test/node_modules/graphql/index.js:1)
    at Object.module.exports.t.a [as call] (/std-esm-module-test/node_modules/@std/esm/esm.js:1)
@dnalborczyk
Copy link
Contributor Author

I'll try to come up with a test case in the meanwhile without a 3rd-party-dependency.

@jdalton
Copy link
Member

jdalton commented Feb 19, 2018

Hi @dnalborczyk!

Could you create a simple repro repo for me to look at?
It's fine if it has a third-party dep.

@dnalborczyk
Copy link
Contributor Author

dnalborczyk commented Feb 19, 2018

@jdalton sure thing, here you go: https://github.com/dnalborczyk/stdesm-graphql

I added a couple of npm convinience scripts:

"start-stdesm-cjs": "node -r @std/esm index.js",
"start-stdesm-esm": "node -r @std/esm index.mjs",
"start-node-esm": "node --experimental-modules index.mjs"

edit:
to see it working pre-v0.13.1, just

npm install graphql@0.13.0

and change ...

import { execute, subscribe } from 'graphql'

to

import graphql from 'graphql'
const { execute, subscribe } = graphql

in index.js and index.mjs.

thanks for looking into this!!

@jdalton jdalton added the bug label Feb 20, 2018
@jdalton
Copy link
Member

jdalton commented Feb 20, 2018

@dnalborczyk Ok thanks!

I found the issue. It comes down to a simple check d851897.

Update:

Hey @dnalborczyk!

I have to pay the unit test debt for this tomorrow. You wouldn't be up for creating a PR with a scenario test for this would you?

@dnalborczyk
Copy link
Contributor Author

cool, thanks!!! yeah, I'll try to add a scenario test.

@dnalborczyk
Copy link
Contributor Author

dnalborczyk commented Feb 21, 2018

added scenario test #288

it's the best I could come up with. I must admit I got confused along the way ... 😃

@jdalton
Copy link
Member

jdalton commented Feb 24, 2018

v0.23.0 is released 🎉

@dnalborczyk
Copy link
Contributor Author

just confirmed, works beautifully! thank you for the fix!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

2 participants