Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect work on Linux (Error: resolve must be run directly as an executable) #316

Closed
vvscode opened this issue Sep 15, 2023 · 0 comments
Closed

Comments

@vvscode
Copy link

vvscode commented Sep 15, 2023

As continue to #315

I faced a problem, when locally(on Mac) everything works, and on CI (Linux) - not I got Error: resolve must be run directly as an executable

after some investigation I discovered that

// DEBUG PATCH
console.log('@@resolve debug info:', JSON.stringify({
    npm_lifecycle_script: process.env.npm_lifecycle_script,
    argv: process.argv,
    __filename,
    ino1: fs.statSync(process.argv[1]).ino,
    ino2: fs.statSync(__filename).ino,
    _: process.env._,
    realpathSync: fs.realpathSync(path.resolve(process.env._))
}, null, 2), { version: pkg.version});

// ---------

if (
    String(process.env.npm_lifecycle_script).slice(0, 8) !== 'resolve '
    && (
        !process.argv
        || process.argv.length < 2
        || (process.argv[1] !== __filename && fs.statSync(process.argv[1]).ino !== fs.statSync(__filename).ino)
        || (process.env._ && fs.realpathSync(path.resolve(process.env._)) !== __filename)
    )
) {
    console.error('Error: `resolve` must be run directly as an executable');
    process.exit(1);
}

gives me different results in section _ (process.env._)

On Mac (locally):

➜  tmp npx resolve 123
@@resolve debug info: {
  "npm_lifecycle_script": "resolve",
  "argv": [
    "/opt/homebrew/Cellar/node/20.6.0/bin/node",
    "/Users/v.vanchuk/repo/tmp/node_modules/.bin/resolve",
    "123"
  ],
  "__filename": "/Users/v.vanchuk/repo/tmp/node_modules/resolve-with-debug/bin/resolve",
  "ino1": 4677520,
  "ino2": 4677520,
  "_": "/Users/v.vanchuk/repo/tmp/node_modules/.bin/resolve",
  "realpathSync": "/Users/v.vanchuk/repo/tmp/node_modules/resolve-with-debug/bin/resolve"
} { version: '1.22.10' }
/Users/v.vanchuk/repo/tmp/node_modules/resolve-with-debug/lib/sync.js:115
    throw err;
    ^

Error: Cannot find module '123' from '/Users/v.vanchuk/repo/tmp'

On Linux (I used github codespaces to reproduce):

@vvscode ➜ /workspaces/codespaces-blank $ npx resolve 123
@@resolve debug info: {
  "npm_lifecycle_script": "resolve",
  "argv": [
    "/usr/local/share/nvm/versions/node/v20.6.1/bin/node",
    "/workspaces/codespaces-blank/node_modules/.bin/resolve",
    "123"
  ],
  "__filename": "/workspaces/codespaces-blank/node_modules/resolve-with-debug/bin/resolve",
  "ino1": 1453838,
  "ino2": 1453838,
  "_": "/home/codespace/nvm/current/bin/npx",
  "realpathSync": "/usr/local/share/nvm/versions/node/v20.6.1/lib/node_modules/npm/bin/npx-cli.js"
} { version: '1.22.10' }
Error: `resolve` must be run directly as an executable

Steps to reproduce:

  • create empty project with npm init -y
  • add latest version of resolve with yarn add resolve@latest
  • run yarn run resolve 123
  • run npx resolve 123
@ljharb ljharb closed this as completed in 1e230d1 Sep 15, 2023
ljharb added a commit that referenced this issue Sep 15, 2023
ljharb added a commit that referenced this issue Sep 15, 2023
 - [Fix] allow `npx resolve` to work (#316)
 - [actions] use reusable rebase action
ljharb added a commit that referenced this issue Sep 15, 2023
v1.22.6

 - [Fix] allow `npx resolve` to work (#316)
 - [actions] use reusable rebase action
ljharb added a commit that referenced this issue Oct 10, 2023
Changes since v2.0.0-next.4:

 - [Fix] fix `npx resolve` by handling symlinks (#315)
 - [Fix] allow `npx resolve` to work (#316)
 - [Tests] rename innocent test project to avoid flawed security scanners
 - [Tests] avoid publishing "malformed package.json" test to avoid flawed security scanners

Including all changes in v1.20.2 - v1.22.8

v1.22.8
 - [Tests] rename innocent test project to avoid flawed security scanners

v1.22.7

 - [Tests] avoid publishing "malformed package.json" test to avoid flawed security scanners

v1.22.6

 - [Fix] allow `npx resolve` to work (#316)
 - [actions] use reusable rebase action

v1.22.5

 - [Fix] fix `npx resolve` by handling symlinks (#315)
 - [Dev Deps] update `array.prototype.map`

v1.22.4

 - Revert "[Refactor] deprecated `lib/core.js` now uses data from `is-core-module` also"
 - [Deps] update `is-core-module`
 - [Dev Deps] update `@ljharb/eslint-config`, `aud`, `semver`, `tape`
 - [meta] commit published core.json data

v1.22.3

 - [Refactor] deprecated `lib/core.js` now uses data from `is-core-module` also
 - [Deps] update `is-core-module`

v1.22.2

 - [Refactor] deprecated `lib/core.js` now uses `is-core-module`
 - [meta] cp core.json on prepack instead of prepublishOnly
 - [Deps] update `is-core-module`
 - [Dev Deps] update `@ljharb/eslint-config`, `aud`, `tape`, `array.prototype.map`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant