tj / node-migrate

Abstract migration framework for node
MIT License
1.53k stars 221 forks source link

Using yarn 2 pnp with package.json scripts cause `ENOTDIR` #184

Open Gisleburt opened 3 years ago

Gisleburt commented 3 years ago

I've added migrate to my package json so that it always passes in the correct store, complier and template options¹

If I try to use it directly, eg:

{
  "scripts": {
    "migrate-create": "migrate create --template-file=\"./migrations-meta/template.ts\" --compiler=\"ts:./migrations-meta/compiler.js\"",
  }
}

When I run it with yarn 2 I get the following error

$ yarn run migrate-create test
internal/child_process.js:407
    throw errnoException(err, 'spawn');
    ^

Error: spawn ENOTDIR
    at ChildProcess.spawn (internal/child_process.js:407:11)
    at spawn (child_process.js:548:9)
    at Command.executeSubCommand (./.yarn/cache/commander-npm-2.20.3-d8dcbaa39b-b73428e97d.zip/node_modules/commander/index.js:562:14)
    at Command.parse (./.yarn/cache/commander-npm-2.20.3-d8dcbaa39b-b73428e97d.zip/node_modules/commander/index.js:488:17)
    at Object.<anonymous> (./.yarn/cache/migrate-npm-1.7.0-d0c8b01ed6-666dcd3e4d.zip/node_modules/migrate/bin/migrate:15:4)
    at Module._compile (internal/modules/cjs/loader.js:1137:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
    at Module.load (internal/modules/cjs/loader.js:985:32)
    at Function.external_module_.Module._load (./.pnp.js:20698:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12) {
  errno: 'ENOTDIR',
  code: 'ENOTDIR',
  syscall: 'spawn'
}

I have a work around by prefixing migrate with npx which then installs and runs a global version of migrate.

We're using yarn 2 with pnp, however other binaries run ok. Did I miss something?

¹ Is there a runtime configuration (rc) file that I missed or isn't not documented so that I don't have to do this?

wesleytodd commented 3 years ago

I am fairly confident that this package will not work with yarn pnp. They do some extensive overriding of node internals and this package uses some dynamic imports which IIRC will break. I don't use yarn and especially not with pnp, but if you can find a fix which is backward compatible I am happy to take a PR.

polad commented 1 year ago

@Gisleburt I experienced a similar issue after switching to Yarn berry v3.3.1 with "Zero Installs" and resolved it by unplugging the migrate package like so:

> yarn unplug migrate

This will unpack the cached zip archive of the migrate package under the .yarn/unplugged/ folder. This will also reference the migrate package in the package.json under dependenciesMeta so that yarn treats this package as unplugged during the future installs. This means the package will be unpacked for everyone doing yarn install. The good news is the package archive will still be cached under .yarn/cache (i.e. checked into git repo) so it won't download it.

Here is more info from yarn docs: https://yarnpkg.com/cli/unplug

Hope it helps anyone using this package.