rollup/rollup-plugin-node-resolve

Symlink resolution

scola84 opened this issue · 7 comments

This line is wrong: https://github.com/rollup/rollup-plugin-node-resolve/blob/master/src/index.js#L74

/project/packageA/index.js
/project/packageA/node_modules/async
/project/packageA/node_modules/packageB as symlink
/project/packageB/index.js

packageA includes packageB and packageB includes async. But async lives under packageA as per how npm installs packages (cf. https://docs.npmjs.com/cli/dedupe).

Now, because of the L74, packageB gets resolved to /project/packageB and rollup tries to import async from packageB/node_modules/async, which does not exist.

Perhaps related to #98. Can you provide a repro?

I solved my problem by setting opts.main = false. This will force disregardResult = true on line https://github.com/rollup/rollup-plugin-node-resolve/blob/master/src/index.js#L65 which in turn will force skipping the if block starting at https://github.com/rollup/rollup-plugin-node-resolve/blob/master/src/index.js#L72

This works with the following plugins:

plugins: [
    resolve({
      main: false
    }),
    commonjs(),
    css({
      output: 'dist/browser.css'
    }),
    buble(),
    livereload({
      watch: 'dist',
      https: {
        ...
      }
    })
]

Now that main has been deprecated in the latest version this workaround requires an alternative syntax to avoid the deprecation message.

  resolve({ mainFields: ['module'] })

This no longer repros. Probably fixed by some of the recent symlinking improvements across this plugin, rollup-plugin-commonjs, and browserify/resolve. Please re-open if this is still an issue!

@bterlson Hello. 👋

I just updated my rollup packages and commented out the workaround and the issue still seems to be present for me. What this screenshot is showing is that the files I'm importing from symlinked folders are not being found. I'm not sure if it matters, but the symlink that I'm using in my project is a relative softlink. In my project I have a root level folder called lib that I link into multiple apps' src folders like this.

# mac
ln -s ../../../lib apps/foobar/src

# win
mklink /D apps\foobar\src\lib ..\..\..\lib

untitled

EDIT: Also, fwiw, this was working in version 2.0.0 and prior.

I created an updated repro in this repository.
https://github.com/whaaaley/symlink-bug

npm i && npm start