Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relative external modules resolve to the wrong place when CWD too short #2901

Closed
mattdrose opened this issue Jun 6, 2019 · 2 comments · Fixed by #2902
Closed

Relative external modules resolve to the wrong place when CWD too short #2901

mattdrose opened this issue Jun 6, 2019 · 2 comments · Fixed by #2902

Comments

@mattdrose
Copy link

  • Rollup Version: 1.14.2
  • Operating System (or Browser): macOS, and Linux
  • Node Version: v10.15.2

How Do We Reproduce?

  1. Import a module that jumps up a couple directories
  2. Build as an external cjs module
  3. Mock process.cwd() to have less depth than the directories you jumped back

There's a REPL here: https://repl.it/@mattdrose/CiRollupExample

Expected Behavior

import Foo from '../../foo';

becomes

const Foo = require('../../foo');

Actual Behavior

import Foo from '../../foo';

becomes

const Foo = require('../foo');

Why is this happening?

I was able to trace the issue to this line:

let relPath = this.id ? normalize(relative(dirname(this.id), depId)) : depId;

This resolves to:

path.relative('.', '../../foo');

Since node's path.relative is relative to process.cwd(), if process.cwd() offers less directories than what you're trying to jump back, it will begin to omit ../'s.

Having a cwd close to / is common in CI environments.

@lukastaegert
Copy link
Member

Thanks, fix at #2901

@mattdrose
Copy link
Author

Thanks so much for a quick fix 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants