Skip to content

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

Closed

Description

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions