You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Resolve doesn't resolve real path for basedir if it is relative path #177
It seems like you're not setting the preserveSymlinks option to false, (it currently defaults to true in v1, altho master has the breaking change of defaulting it to false).
hmm, i'm trying to reproduce this error, and i do get this failure: Cannot find module '../../node_modules/jquery' from './node_modules/@my-scope/package-b'
However, after npm installand after npx lerna bootstrap, node_modules still lacks a @my-scope directory, so i'm not sure why you'd expect something to be resolved there.
OK, but the error says "from node_modules/@my-scope/package-b" - and then "../../node_modules/jquery'" - so, the final path it's looking for is "node_modules/jquery" (inside package-a) - but package-a doesn't have jquery listed as a dependency, and it's not present on disk.
/Users/malash/Projects/resolve-bad-case/node_modules/jquery/dist/jquery.js
/Users/malash/Projects/resolve-bad-case/node_modules/resolve/lib/sync.js:46
throw err;
^
Error: Cannot find module '../../node_modules/jquery' from '/Users/malash/Projects/resolve-bad-case/packages/package-a/node_modules/@my-scope/package-b'
at Function.module.exports [as sync] (/Users/malash/Projects/resolve-bad-case/node_modules/resolve/lib/sync.js:44:15)
at Object.<anonymous> (/Users/malash/Projects/resolve-bad-case/packages/package-a/index.js:8:21)
at Module._compile (internal/modules/cjs/loader.js:707:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:718:10)
at Module.load (internal/modules/cjs/loader.js:605:32)
at tryModuleLoad (internal/modules/cjs/loader.js:544:12)
at Function.Module._load (internal/modules/cjs/loader.js:536:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:760:12)
at startup (internal/bootstrap/node.js:303:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:872:3)
The current logic equals to path.resolve because of this line :
OK, so part of the problem is that the basedir you're passing in isn't resolved - it's relative to package-a/index, but that's not information that resolve can retain - so you first have to path.resolve(__dirname, './node_modules/@my-scope/package-b').
This makes the first assertion pass, but the second still fails for me.
Normally the basedir should be absolute path. It's my fault to pass a relative path for basedir in the first version test case so I fixed it. That could be another good question how relative basedir resolved.
For this issue the inconsistency is that user have to resolve real path of basedir for relative path but not NPM package.
It seems like you're not setting the preserveSymlinks option to false, (it currently defaults to true in v1, altho master has the breaking change of defaulting it to false).
Did this breaking change get resolved before publishing v1.9.0?
@john-kurkowski v1.9.0 does not include any of the breaking changes. I cherry-picked commits onto the v1.8.1 tag, and released, and merged the v1.9.0 tag back to master.
Problem is that with path ./components/cmp-a/cmp-a.js and { basedir: '/src' } , [email protected] gives an error through the callback
`Error: Cannot find module './components/cmp-a/cmp-a.js' from '/src'
, but [email protected] does the fs.realpath check and then calls init(undefined) which throws
TypeError: Path must be a string. Received undefined
and makes the code fail.
When I replaced init(realStart) with init(realStart || absoluteStart), it was fixed... but I guess the problem could also be that the base dir is an absolute path /src even though that is meant as a relative path ./src in this case (adding if (basedir === '/src') basedir = './src'; also fixed it).
I'm not that familiar with the topic so what would you suggest? Is this more related to bad code that needs to be fixed, or should I wait for the fix?
Activity
ljharb commentedon Nov 27, 2018
It seems like you're not setting the
preserveSymlinksoption tofalse, (it currently defaults totruein v1, altho master has the breaking change of defaulting it tofalse).What happens if you set that option?
malash commentedon Nov 27, 2018
I update the test case and the bug still exists.
malash/resolve-issue-177@c5ea1c8
In fact
preserveSymlinksisn't used at all in https://github.com/browserify/resolve/blob/master/lib/sync.js#L49-L52ljharb commentedon Nov 28, 2018
hmm, i'm trying to reproduce this error, and i do get this failure:
Cannot find module '../../node_modules/jquery' from './node_modules/@my-scope/package-b'However, after
npm installand afternpx lerna bootstrap,node_modulesstill lacks a@my-scopedirectory, so i'm not sure why you'd expect something to be resolved there.malash commentedon Nov 29, 2018
@ljharb I will clarify it.
When running
node packages/package-ait equals to
cd packages/package-a && node ./index.jsso the
basedirwould bethe-repo/packages/package-a/node_modules/@my-scope/package-bwhich is a symlink to
the-repo/packages/package-b.ljharb commentedon Nov 29, 2018
OK, but the error says "from node_modules/@my-scope/package-b" - and then "../../node_modules/jquery'" - so, the final path it's looking for is "node_modules/jquery" (inside package-a) - but package-a doesn't have jquery listed as a dependency, and it's not present on disk.
ljharb commentedon Nov 29, 2018
(and package-b doesn't have jquery either)
malash commentedon Nov 29, 2018
No. The final path is not
'node_modules/jquery'but'packages/package-a/node_modules/node_modules/jquery'and it's wrong even ifpackage-ahadjquery.First, I fixed the
basedirin test case with abs path so the error trace is more clear.The current logic equals to
path.resolvebecause of this line :'/path/to/repo/packages/package-a/node_modules/@my-scope/package-b'+
'../../node_modules/jquery'=>
'/path/to/repo/packages/package-a/node_modules/node_modules/jquery'It's a non-exist path.
The correct way should be:
basedir. E.g.'/path/to/repo/packages/package-a/node_modules/@my-scope/package-b'=>'/path/to/repo/packages/package-b/''/path/to/repo/packages/package-b/'+'../../node_modules/jquery'=>/path/to/repo/node_modules/jqueryThat line could be refactor like this ( just for demo ):
ljharb commentedon Nov 29, 2018
Got it, thanks for explaining.
ljharb commentedon Nov 29, 2018
OK, so part of the problem is that the basedir you're passing in isn't resolved - it's relative to package-a/index, but that's not information that resolve can retain - so you first have to
path.resolve(__dirname, './node_modules/@my-scope/package-b').This makes the first assertion pass, but the second still fails for me.
malash commentedon Nov 30, 2018
Normally the
basedirshould be absolute path. It's my fault to pass a relative path forbasedirin the first version test case so I fixed it. That could be another good question how relativebasedirresolved.For this issue the inconsistency is that user have to resolve real path of basedir for relative path but not NPM package.
malash commentedon Nov 30, 2018
Compression between
preserveSymlinks === trueandpreserveSymlinks === falsemalash commentedon Dec 17, 2018
@ljharb Thank you very much for your commit. This commit works for me.
ljharb commentedon Dec 17, 2018
Thank you for your excellent repro case!
[Fix] `sync`/`async`: fix `preserveSymlinks` option
v1.9.0
john-kurkowski commentedon Dec 19, 2018
Did this breaking change get resolved before publishing v1.9.0?
master(04e6c79) has a different checkresolve/lib/async.js
Line 57 in 04e6c79
vs. what I think was published at tag v1.9.0.
https://github.com/browserify/resolve/blob/v1.9.0/lib/sync.js#L36
ljharb commentedon Dec 19, 2018
@john-kurkowski v1.9.0 does not include any of the breaking changes. I cherry-picked commits onto the v1.8.1 tag, and released, and merged the v1.9.0 tag back to master.
simonhaenisch commentedon Jan 11, 2019
@ljharb what are the plans on releasing this fix? Having issues with this in stenciljs/core#1310.
[email protected]uses[email protected]and[email protected]uses[email protected].Problem is that with path
./components/cmp-a/cmp-a.jsand{ basedir: '/src' },[email protected]gives an error through the callback, but
[email protected]does thefs.realpathcheck and then callsinit(undefined)which throwsand makes the code fail.
When I replaced
init(realStart)withinit(realStart || absoluteStart), it was fixed... but I guess the problem could also be that the base dir is an absolute path/srceven though that is meant as a relative path./srcin this case (addingif (basedir === '/src') basedir = './src';also fixed it).I'm not that familiar with the topic so what would you suggest? Is this more related to bad code that needs to be fixed, or should I wait for the fix?
ljharb commentedon Jan 11, 2019
@simonhaenisch it’s released in v1.9.0. If you’re still seeing a problem, please file a new issue and we can talk it out there.