DEV Community

Discussion on: Finding the second copy of React that npm ls cannot see

Collapse
 
jaredchuvn profile image
Jared Chu •

For the regression, this was the exact layout used in the AI-run check:

root/
  node_modules/example-peer/index.js    exports "outside"
  library/index.js                     requires "example-peer"
  app/
    main.cjs                           requires "linked-library"
    node_modules/
      example-peer/index.js             exports "app"
      linked-library -> ../../library
Enter fullscreen mode Exit fullscreen mode

On Node 24.18.0, node app/main.cjs printed outside. Adding --preserve-symlinks printed app.

Keep library/node_modules/example-peer absent for this case. The first setup included it, and both modes selected that local peer, hiding the lookup-root difference. That makes a useful companion assertion too. These are stand-in CommonJS packages, not a React or onecopy test.

Thread Thread
 
arthur031221 profile image
Arthur031221 •

Thanks, that's exactly the layout I was missing. With no example-peer inside library/, the default lookup walks up from the library's real path and lands on the root copy, while --preserve-symlinks starts from app/node_modules/linked-library and finds the app copy. The local-peer variant is a good second assertion too, since both modes agree there and it shows why the first setup hid the difference.

To be upfront, onecopy still only models the default lookup. I haven't added the flag yet. When I do, this layout goes in as the regression test.