standard-things / esm

Tomorrow's ECMAScript modules today!
Other
5.27k stars 147 forks source link

"Error: Module did not self-register" — since v0.19.0 #213

Closed maxmilton closed 6 years ago

maxmilton commented 6 years ago

Since version 0.19.0 I've had this error appear when starting node:

yarn run v1.3.2
$ NODE_ENV=development DEBUG=koa* node ./src/index.js
Error: Module did not self-register.
    at bindings (file:///home/max/example/node_modules/bindings/bindings.js:81:44)
    at Object.<anonymous> (file:///home/max/example/node_modules/couchbase/lib/binding.js:197:36)
    at Object.<anonymous> (file:///home/max/example/node_modules/couchbase/lib/binding.js:1)
    at Object.<anonymous> (file:///home/max/example/node_modules/couchbase/lib/couchbase.js:3:15)
    at Object.<anonymous> (file:///home/max/example/node_modules/couchbase/lib/couchbase.js:1)
    at Object.<anonymous> (file:///home/max/example/src/db/index.mjs:1)
    at Object.<anonymous> (file:///home/max/example/src/db/index.mjs:1)
    at Object.<anonymous> (file:///home/max/example/src/graphql/resolvers.mjs:1)
    at Object.<anonymous> (file:///home/max/example/src/graphql/resolvers.mjs:1)
    at Object.<anonymous> (file:///home/max/example/src/graphql/index.mjs:1)
    at Object.<anonymous> (file:///home/max/example/src/graphql/index.mjs:1)
    at Object.<anonymous> (file:///home/max/example/src/router/index.mjs:1)
    at Object.<anonymous> (file:///home/max/example/src/router/index.mjs:1)
    at Object.<anonymous> (file:///home/max/example/src/app.mjs:1)
    at Object.<anonymous> (file:///home/max/example/src/app.mjs:1)
    at Object.<anonymous> (file:///home/max/example/src/main.mjs:1)
    at Object.<anonymous> (file:///home/max/example/src/main.mjs:1)
    at Object.<anonymous> (file:///home/max/example/src/index.js:5:18)
    at Module._compile (module.js:660:30)
    at Object.Module._extensions..js (module.js:671:10)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
    at Function.Module.runMain (module.js:701:10)
    at startup (bootstrap_node.js:194:16)
    at bootstrap_node.js:618:3
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Not sure as to what's going on to be honest. Here's the source for the bindings.js from the stacktrace. Also my index.js:

'use strict';

require = require('@std/esm')(module, { cjs: true }); // eslint-disable-line no-global-assign
module.exports = require('./main.mjs').default;

Things work normally after reverting back to version 0.18.0.

jdalton commented 6 years ago

Hi @MaxMilton!

It looks like this is a bindings.js issue. Have you tried deleting your node_modules folder and reinstalling everything?

Update:

~~It looks like the npm registry is experiencing issues at the moment. Related to https://github.com/npm/npm/issues/18434#issuecomment-355775144.~~

Update:

The npm registry issue is resolved.

maxmilton commented 6 years ago

The problem still persists even after removing the node_modules directory and the npm and yarn caches.

jdalton commented 6 years ago

Could you create a small repro repo for me to look at?

chrillo commented 6 years ago

I had a similar issue, first I started getting the same error, after repeatedly to remove node_modules and reinstalling the error changed from this to "[ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string" in serveral packages on of them beeing express which I have working in an other project with 0.19.1 ... does @std/esm do any caching somewhere on its own. since this seems so eradic and inconsistent it looks like something npm / caching related. going back to 0.18.0 also fixed it for me.

maxmilton commented 6 years ago

@jdalton I've put together a repo with a minimal reproduction of the bug: https://github.com/MaxMilton/reproduce-esm-bug

I've put comments etc. to try to explain things but please let me know if there's anything else I can help with! :)

jdalton commented 6 years ago

Thank you @MaxMilton! I can reproduce the error too! Digging in...

Update:

Found the bug! When in the parsing mode I didn't skip non-js compilers so the .node compile was happening twice which caused the Module did not self-register to be thrown.

Update:

Patched https://github.com/standard-things/esm/commit/9147ba7c31e85064f1eb6b5a64e2a5e4bb165587, https://github.com/standard-things/esm/commit/07d83bf7a1e3c1f1aa2fbf9ff659fac5fec1b5a1, https://github.com/standard-things/esm/commit/53b62705407299dce2969f137ab5bb065b847f76.

maxmilton commented 6 years ago

Nice catch! :star2: :100:

jdalton commented 6 years ago

v0.19.3 is released :tada: