resolve: `npx resolve` errors

I have the error, so I added some debug info upfront:

console.log({
    npm_lifecycle_script: process.env.npm_lifecycle_script,
    _: process.env._,
    __filename
})

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._ && path.resolve(process.env._) !== __filename)
    )
) {
    console.error('Error: `resolve` must be run directly as an executable');
    process.exit(1);
}

that gives me:

{
  npm_lifecycle_script: 'resolve',
  _: '/Users/v.vanchuk/repo/test/node_modules/.bin/resolve',
  __filename: '/Users/v.vanchuk/repo/test/node_modules/resolve/bin/resolve'
}

I failed to follow the logic in this place

  • when npm_lifecycle_script can have space at the end?
  • why in general you make this restriction? (what’s the purpose?)

Hope you can help / clarify this moment =)

Thanks in advance

About this issue

  • Original URL
  • State: closed
  • Created 10 months ago
  • Comments: 17 (7 by maintainers)

Commits related to this issue

Most upvoted comments

I proposed once, this mention was just to inform you about the state of that API. Thanks for helping me with the issues

Good luck

require.main is deprecated and something that should never, ever have existed; i’m not going to use it.

And to ensure it can’t be required/imported.

v1.22.5 is published.

There’ll be no need for that workaround; i’ll have a release cut momentarily.