rdkcentral / Lightning-SDK

SDK for Lightning framework
Apache License 2.0
130 stars 69 forks source link

Unable to install @lightning/sdk with NPM version 7 #134

Closed jhderojasUVa closed 4 years ago

jhderojasUVa commented 4 years ago

Hi,

If you have npm version 7.0.2 (included on node 15) you are unable to install lightning/sdk because the post-install scripts fails:

 npm ERR! path /builds/lightning/applications/XXXXXXXXXXX/node_modules/@lightningjs/sdk
 npm ERR! command failed
 npm ERR! command sh -c node ./scripts/postinstall.js
 npm ERR! mkdir: path already exists: /builds/lightning/applications/XXXXXXXXXXX/node_modules/@lightningjs/sdk/support
 npm ERR! node:internal/validators:123
 npm ERR!     throw new ERR_INVALID_ARG_TYPE(name, 'string', value);
 npm ERR!     ^
 npm ERR! 
 npm ERR! TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
 npm ERR!     at new NodeError (node:internal/errors:258:15)
 npm ERR!     at validateString (node:internal/validators:123:11)
 npm ERR!     at Object.join (node:path:1039:7)
 npm ERR!     at Object.<anonymous> (/builds/lightning/applications/XXXXXXXXXXX/node_modules/@lightningjs/sdk/scripts/postinstall.js:61:34)
 npm ERR!     at Module._compile (node:internal/modules/cjs/loader:1083:30)
 npm ERR!     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1112:10)
 npm ERR!     at Module.load (node:internal/modules/cjs/loader:948:32)
 npm ERR!     at Function.Module._load (node:internal/modules/cjs/loader:789:14)
 npm ERR!     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:72:12)
 npm ERR!     at node:internal/main/run_main_module:17:47 {
 npm ERR!   code: 'ERR_INVALID_ARG_TYPE'
 npm ERR! }

This error shows that the line that is failing is:

const packageJson = require(path.join(process.env.INIT_CWD, 'package.json'))

Because the process.env.INIT_CWD returns undefined on npm 7.0.2

If you change the npm version to something below it will work with no problem.

You can reproduce the problem by creating a simple js file and run it as script on the package.json file (in order to make it run with the npm). For example

javascript.js

console.log(process.env.INIT_CWD)

package.json

.... THE NORMAL THINGS
"scripts": { "runme": "node ./javascript.js" }
.... THE NORMAL THINGS

And then run: npm run runme

This will shout you on the shell/bash/what you use: undefined

With other versions on npm will show the path of where the npm is called (the normal behaviour).

michielvandergeest commented 4 years ago

Quick update on this: I can confirm the same behaviour with npm@7.0.3 ..

In the mean time a bug report has been opened on the NPM github about INIT_CWD missing: https://github.com/npm/cli/issues/2033. This is what ultimately is breaking things. So let's keep an eye on that one.

In the mean time I will apply an extra check for the existence of INIT_CWD to the SDK install script, so it won't error out.

jhderojasUVa commented 4 years ago

The fix is working. Now it's time to wait until the official patch into npm or merge this :)

michielvandergeest commented 4 years ago

Cool! Merged into the dev-branch. Will be released soon.