Skip to content
This repository has been archived by the owner on Sep 16, 2023. It is now read-only.

global module usage of esm throws #702

Closed
dnalborczyk opened this issue Jan 8, 2019 · 9 comments
Closed

global module usage of esm throws #702

dnalborczyk opened this issue Jan 8, 2019 · 9 comments
Labels

Comments

@dnalborczyk
Copy link
Collaborator

dnalborczyk commented Jan 8, 2019

after #699 I noticed tink is using esm under the hood and was reminded to give it a try again.

tools:
nvs 1.5.1
tink 0.20.0
node 11.6.0
macOS 10.14.3 beta

since there are quite a lot of tools involved, it could very well be that it's not an esm bug.

when running e.g. tink add graphql the following exception is thrown:

Cannot read property 'cachePath' of null [which is thrown by esm I believe]

although tink is was using a slightly modified fork of esm, I installed esm v3.0.84 next to tink, which then was throwing:

node[94656]: ../src/node_file.cc:1375:void node::fs::RealPath(const FunctionCallbackInfo<v8::Value> &): Assertion `(argc) >= (3)' failed.
 1: 0x100063a65 node::Abort() [/Users/daniel/.nvs/default/bin/node]
 2: 0x100063997 node::PrintErrorString(char const*, ...) [/Users/daniel/.nvs/default/bin/node]
 3: 0x10007006a node::fs::RealPath(v8::FunctionCallbackInfo<v8::Value> const&) [/Users/daniel/.nvs/default/bin/node]
 4: 0x100224b27 v8::internal::FunctionCallbackArguments::Call(v8::internal::CallHandlerInfo*) [/Users/daniel/.nvs/default/bin/node]
 5: 0x1002240f6 v8::internal::MaybeHandle<v8::internal::Object> v8::internal::(anonymous namespace)::HandleApiCallHelper<false>(v8::internal::Isolate*, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::FunctionTemplateInfo>, v8::internal::Handle<v8::internal::Object>, v8::internal::BuiltinArguments) [/Users/daniel/.nvs/default/bin/node]
 6: 0x1002237f0 v8::internal::Builtin_Impl_HandleApiCall(v8::internal::BuiltinArguments, v8::internal::Isolate*) [/Users/daniel/.nvs/default/bin/node]
 7: 0x18c3becfb7d 
[1]    94656 abort      tink add graphql

then I tried to use the head of master: npm i github:standard-things/esm, incl. deleting the cache prior:

/Users/daniel/.nvs/node/11.6.0/x64/lib/node_modules/tink/node_modules/esm/esm.js:1
var __global__ = this;(function (require, module, __jest__, __shared__) { var __shared__;const e=module,t={Array:global.Array,Buffer:global.Buffer,Error:global.Error,EvalError:global.EvalError,Function:global.Function,JSON:global.JSON,Object:global.Object,Promise:global.Promise,RangeError:global.RangeError,ReferenceError:global.ReferenceError,Reflect:global.Reflect,SyntaxError:global.SyntaxError,TypeError:global.TypeError,URIError:global.URIError,eval:global.eval},r=global.console;module.exports=(function(e){var t={};function r(i){if(t[i])return t[i].exports;var n=t[i]={i:i,l:!1,exports:{}};return e[i].call(n.exports,n,n.exports,r),n.l=!0,n.exports}return r.d=function(e,t,r){Reflect.defineProperty(e,t,{configurable:!0,enumerable:!0,get:r})},r.n=function(e){return e.a=e,function(){return e}},r(r.s=2)})([(function(e,t){var r;t=e.exports=K,"object"==typeof process&&process,r=function(){},t.SEMVER_SPEC_VERSION="2.0.0";var i=256,n

TypeError: Cannot read property 'cachePath' of null
    at Kc.<anonymous> (/Users/daniel/.nvs/node/11.6.0/x64/lib/node_modules/tink/node_modules/esm/esm.js:1:234054)
    at Kc.<anonymous> (/Users/daniel/.nvs/node/11.6.0/x64/lib/node_modules/tink/node_modules/esm/esm.js:1:27269)
    at Kc.<anonymous> (/Users/daniel/.nvs/node/11.6.0/x64/lib/node_modules/tink/node_modules/esm/esm.js:1:234155)
    at Kc.<anonymous> (/Users/daniel/.nvs/node/11.6.0/x64/lib/node_modules/tink/node_modules/esm/esm.js:1:27269)
    at Kc.<anonymous> (/Users/daniel/.nvs/node/11.6.0/x64/lib/node_modules/tink/node_modules/esm/esm.js:1:234501)
    at Kc.<anonymous> (/Users/daniel/.nvs/node/11.6.0/x64/lib/node_modules/tink/node_modules/esm/esm.js:1:27269)
    at yp (/Users/daniel/.nvs/node/11.6.0/x64/lib/node_modules/tink/node_modules/esm/esm.js:1:245127)
    at lh (/Users/daniel/.nvs/node/11.6.0/x64/lib/node_modules/tink/node_modules/esm/esm.js:1:260383)
    at makeRequireFunction (/Users/daniel/.nvs/node/11.6.0/x64/lib/node_modules/tink/node_modules/esm/esm.js:85:19)
    at Object.<anonymous> (/Users/daniel/.nvs/node/11.6.0/x64/lib/node_modules/tink/bin/tink.js:5:25)
@jdalton jdalton added the bug label Jan 13, 2019
@jdalton
Copy link
Member

jdalton commented Jan 13, 2019

Hi @dnalborczyk!

With our current master branch and tink's master branch, modified to enable esm, I can not reproduce this issue. Could you test and see if it's resolved for you?

@jdalton jdalton closed this as completed Jan 13, 2019
@dnalborczyk
Copy link
Collaborator Author

dnalborczyk commented Jan 14, 2019

just gave it a try, no change in the above with latest master.

but I debugged it a bit, and found the following which might help:

I believe it's throwing essentially here:
https://github.com/standard-things/esm/blob/master/esm.js#L256
dir is null in my case.

btw, is the cachePath the expected location? although it might be unrelated.
https://github.com/standard-things/esm/blob/master/esm.js#L202

in my case, when used with nvs:

__dirname:
/Users/daniel/.nvs/node/11.6.0/x64/lib/node_modules/tink/node_modules/esm

cachePath: /Users/daniel/.nvs/node/11.6.0/x64/lib/node_modules/tink/node_modules/esm/node_modules/.cache/esm

which usually when used locally is the root of the node_modules folder:
/Users/daniel/.nvs/node/11.6.0/x64/lib/node_modules/.cache/esm

I also gave it a try with telling tink to skip the cache https://github.com/npm/tink/blob/v0.20.0/bin/tink.js#L5 with cache: false, but the error remained.

let me now if you need any additional information

good luck at http://www.covalenceconf.com/ btw! I hope it's being made accessible by video afterwards.

@jdalton
Copy link
Member

jdalton commented Jan 14, 2019

Thanks @dnalborczyk!

Could you provide exact repro steps. I tried using npm link'd tink from modified master branches and couldn't repro by just running tink add graphql.

@dnalborczyk
Copy link
Collaborator Author

dnalborczyk commented Jan 15, 2019

the manual repro steps are fairly simple:

npm i nvs -g  # might be not involved in the issue
npm i tink@0.20.0 -g
tink add graphql

if you are familiar with docker, and you don't want to mess with your local setup, I got it re-created without nvs:

# Dockerfile
FROM node:11.6-alpine
RUN npm i tink@0.20.0 -g
RUN mkdir test
RUN cd test
# not sure if tink needs a package.json
RUN npm init -y
RUN tink add graphql
docker build .
Sending build context to Docker daemon    150kB
Step 1/6 : FROM node:11.6-alpine
 ---> 9036ebdbc59d
Step 2/6 : RUN npm i tink@0.20.0 -g
 ---> Using cache
 ---> 1672af935786
Step 3/6 : RUN mkdir test
 ---> Using cache
 ---> 7b9985b29a86
Step 4/6 : RUN cd test
 ---> Using cache
 ---> 4f387486263a
Step 5/6 : RUN npm init -y # not sure if tink needs a package.json
 ---> Using cache
 ---> 7c274e16d435
Step 6/6 : RUN tink add graphql
 ---> Running in 6aa81361bc23
/usr/local/lib/node_modules/tink/node_modules/esm/esm.js:1
var __global__ = this;(function (require, module, __jest__, __shared__) { var __shared__;const e=module,t={Array:global.Array,Buffer:global.Buffer,Error:global.Error,EvalError:global.EvalError,Function:global.Function,JSON:global.JSON,Object:global.Object,Promise:global.Promise,RangeError:global.RangeError,ReferenceError:global.ReferenceError,Reflect:global.Reflect,SyntaxError:global.SyntaxError,TypeError:global.TypeError,URIError:global.URIError,eval:global.eval},r=global.console;module.exports=(function(e){var t={};function r(i){if(t[i])return t[i].exports;var n=t[i]={i:i,l:!1,exports:{}};return e[i].call(n.exports,n,n.exports,r),n.l=!0,n.exports}return r.d=function(e,t,r){Reflect.defineProperty(e,t,{configurable:!0,enumerable:!0,get:r})},r.n=function(e){return e.a=e,function(){return e}},r(r.s=2)})([(function(e,t){var r;t=e.exports=K,"object"==typeof process&&process,r=function(){},t.SEMVER_SPEC_VERSION="2.0.0";var i=256,n=Number.MAX_SAFE_INTEGER

TypeError: Cannot read property 'cachePath' of null
    at Hc.<anonymous> (/usr/local/lib/node_modules/tink/node_modules/esm/esm.js:1:234966)
    at Hc.<anonymous> (/usr/local/lib/node_modules/tink/node_modules/esm/esm.js:1:27269)
    at Hc.<anonymous> (/usr/local/lib/node_modules/tink/node_modules/esm/esm.js:1:235067)
    at Hc.<anonymous> (/usr/local/lib/node_modules/tink/node_modules/esm/esm.js:1:27269)
    at Hc.<anonymous> (/usr/local/lib/node_modules/tink/node_modules/esm/esm.js:1:235413)
    at Hc.<anonymous> (/usr/local/lib/node_modules/tink/node_modules/esm/esm.js:1:27269)
    at vp (/usr/local/lib/node_modules/tink/node_modules/esm/esm.js:1:246039)
    at lh (/usr/local/lib/node_modules/tink/node_modules/esm/esm.js:1:261486)
    at makeRequireFunction (/usr/local/lib/node_modules/tink/node_modules/esm/esm.js:85:19)
    at Object.<anonymous> (/usr/local/lib/node_modules/tink/bin/tink.js:5:25)
The command '/bin/sh -c tink add graphql' returned a non-zero code: 1

update:
one sec, tink v0.20.0 is pointing to the patched branch ...

@dnalborczyk
Copy link
Collaborator Author

just installed from head github:npm/tink, which uses head esm, and the issue seems to be gone! 👍

@jdalton
Copy link
Member

jdalton commented Jan 15, 2019

Thank you for digging into it @dnalborczyk!

Update:

Just checking, when you tested github:npm/tink did you uncomment their esm use?

@dnalborczyk
Copy link
Collaborator Author

dnalborczyk commented Jan 15, 2019

interesting. I didn't comment it out, because I was under the assumption that it was already uncommented again, because I remember seeing the commit history (which looked kinda borked though), with esm being re-activated, but that might have been a couple days ago. it's gone now, probably a --force push.

let me try again ....

@dnalborczyk
Copy link
Collaborator Author

ah, you're right, that was the culprit. it's back again, when uncommented out.

@jdalton
Copy link
Member

jdalton commented Jan 15, 2019

Thanks @dnalborczyk!

I was able to reproduce and have it fixed locally.

Update:

Patched b77cf1a.

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