adnelson / nixfromnpm

Convert NPM packages into nix expressions
MIT License
50 stars 8 forks source link

Bug with handling of namespaced packages? #152

Open paulyoung opened 5 years ago

paulyoung commented 5 years ago

I've come to know that if I create a project that uses webpack, I'm pretty quickly going to run into a problem regarding the @xtuc/long package. It usually manifests as a "runtime" error (when running a webpack build, not a nix compilation error) and looks something like this:

Error: Cannot find module '@xtuc/long'
    at Function.Module._resolveFilename (module.js:548:15)
    at Function.Module._load (module.js:475:25)
    at Module.require (module.js:597:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/nix/store/i1n2pk1j2g56nb2s5xc21wa0kqjdyj0l-=webassemblyjs=-ast-1.7.11-nodejs-8.12.0/lib/node_modules/@webassemblyjs/ast/node_modules/@webassemblyjs/wast-printer/lib/index.js:10:36)
    at Module._compile (module.js:653:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)

Usually I just add @xtuc/long to my package.json and move on, but this time that didn't work so I started investigating further.

In this instance, I verified that the package.json for @webassemblyjs/wast-printer looked reasonable, which it does:

$ cat /nix/store/i1n2pk1j2g56nb2s5xc21wa0kqjdyj0l-=webassemblyjs=-ast-1.7.11-nodejs-8.12.0/lib/node_modules/@webassemblyjs/ast/node_modules/@webassemblyjs/wast-printer/package.json
{
  "name": "@webassemblyjs/wast-printer",
  "version": "1.7.11",
  "description": "WebAssembly text format printer",
  "main": "lib/index.js",
  "module": "esm/index.js",
  "keywords": [
    "webassembly",
    "javascript",
    "ast",
    "compiler",
    "printer",
    "wast"
  ],
  "scripts": {
    "test": "mocha"
  },
  "author": "Sven Sauleau",
  "license": "MIT",
  "dependencies": {
    "@webassemblyjs/ast": "1.7.11",
    "@webassemblyjs/wast-parser": "1.7.11",
    "@xtuc/long": "4.2.1"
  },
  "devDependencies": {
    "@webassemblyjs/helper-test-framework": "1.7.11"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/xtuc/webassemblyjs.git"
  },
  "publishConfig": {
    "access": "public"
  },
  "gitHead": "4291990bfc4648bc6676091a955d12dc3c7e5909"
}

However, there is no node_modules directory:

$ ls /nix/store/i1n2pk1j2g56nb2s5xc21wa0kqjdyj0l-=webassemblyjs=-ast-1.7.11-nodejs-8.12.0/lib/node_modules/@webassemblyjs/ast/node_modules/@webassemblyjs/wast-printer/
LICENSE                 esm                 package.json
README.md               lib                 webassemblyjs-wast-printer-1.7.10.tgz

I looked one level up, and there is a node_modules directory with an @xtuc directory in it:

$ ls /nix/store/i1n2pk1j2g56nb2s5xc21wa0kqjdyj0l-=webassemblyjs=-ast-1.7.11-nodejs-8.12.0/lib/node_modules/@webassemblyjs/ast/node_modules/
@webassemblyjs  @xtuc

But the contents of node_modules/@xtuc did not contain a long directory:

$ ls /nix/store/i1n2pk1j2g56nb2s5xc21wa0kqjdyj0l-=webassemblyjs=-ast-1.7.11-nodejs-8.12.0/lib/node_modules/@webassemblyjs/ast/node_modules/@xtuc
LICENSE     README.md   dist        index.d.ts  index.js    package.json    src

The package.json file in that directory is for the @xtuc/long package:

$ cat /nix/store/i1n2pk1j2g56nb2s5xc21wa0kqjdyj0l-=webassemblyjs=-ast-1.7.11-nodejs-8.12.0/lib/node_modules/@webassemblyjs/ast/node_modules/@xtuc/package.json
{"name":"@xtuc/long","version":"4.2.1","author":"Daniel Wirtz <dcode@dcode.io>","description":"A Long class for representing a 64-bit two's-complement integer value.","module":"src/long.js","main":"dist/long.cjs.js","repository":{"type":"git","url":"https://github.com/dcodeIO/long.js.git"},"bugs":{"url":"https://github.com/dcodeIO/long.js/issues"},"keywords":["math"],"dependencies":{},"devDependencies":{"@babel/cli":"^7.0.0-beta.54","@babel/core":"^7.0.0-beta.54","@babel/plugin-transform-modules-commonjs":"^7.0.0-beta.54","webpack":"^3.10.0"},"license":"Apache-2.0","scripts":{"build":"webpack","test":"node tests"},"files":["index.js","LICENSE","README.md","src/long.js","dist/long.js","dist/long.js.map","index.d.ts"],"types":"index.d.ts","prepublish":"babel --plugins @babel/plugin-transform-modules-commonjs src/long.js -o dist/long.cjs.js"}
paulyoung commented 5 years ago

I tried working around this issue by adding @xtuc/long to my package.json and setting NODE_PATH="$NODE_PATH:node_modules"; but then I encounter problems with missing peerDependencies. Not sure if that is related.

paulyoung commented 5 years ago

FWIW, I'm trying to get an app freshly generated from create-react-app to build.