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

Respect NODE_PATH environment variable #6111

Open
TLATER opened this issue Apr 11, 2021 · 5 comments
Open

Respect NODE_PATH environment variable #6111

TLATER opened this issue Apr 11, 2021 · 5 comments

Comments

@TLATER
Copy link

TLATER commented Apr 11, 2021

🐛 bug report

When trying to build with no node_modules directory, but all my dependencies in a directory listed in NODE_PATH, parcel will fail to run because it cannot resolve its plugins.

I believe this will also extend to bundling modules from the path, since the module resolution is custom and I can't find any references to NODE_PATH in the relevant source files.

🎛 Configuration (.babelrc, package.json, cli command)

This can be reproduced with no configuration at all! See the code sample section.

🤔 Expected Behavior

Parcel should resolve modules correctly according to NODE_PATH, and in the test case output an empty file (I think, I'll admit I'm too lazy to check what parcel outputs for an empty html file right now).

😯 Current Behavior

Parcel complains that even its built-in plugins are missing.

The exact error is:

@parcel/core: Cannot find extended parcel config
/home/tlater/Documents/Projects/tlaternet-templates/.parcelrc:2:15
  1 | {
> 2 |   "extends": ["@parcel/config-default"],
>   |               ^^^^^^^^^^^^^^^^^^^^^^^^ Cannot find module "@parcel/config-default"
  3 |   "transformers": {
  4 |     "*.mp3": [ "@parcel/transformer-raw" ]

💁 Possible Solution

Fix the module resolution to respect NODE_PATH.

🔦 Context

I'm trying to deploy a website on a NixOS host. I'm using node2nix to achieve this, which uses the NODE_PATH variable to allow the package manager to take control of the node_modules.

💻 Code Sample

Easiest reproduction scenario:

  1. mkdir test && pushd test
  2. npm install parcel
    • Make sure you don't have a directory with a node_modules or package*.json in it as any parent directory up to the root.
  3. export NODE_PATH="$(pwd)/node_modules"
  4. popd
  5. touch empty.html
  6. "$NODE_PATH/.bin/parcel" empty.html

🌍 Your Environment

Software Version(s)
Parcel 2.0.0-beta.2
Node v12.21.0
npm/Yarn npm 6.14.11
Operating System NixOS 20.09.20210401.da7f4c4 (Nightingale)
@mischnic
Copy link
Member

NODE_PATH would have to be taken into account in these files:

@josephshen
Copy link

Hi @TLATER check this pull #8273 (comment)

@TLATER
Copy link
Author

TLATER commented Jul 3, 2022

Very cool. Surprisingly tidy and simple, I should have looked at this more closely years ago, been using an ugly hack ever since :)

@toastal
Copy link
Contributor

toastal commented Nov 6, 2023

This would be useful for using npmlock2nix when developing Nix as you can’t run network requests from a Nix derivation.

@ggPeti
Copy link

ggPeti commented Nov 22, 2023

@devongovett please support this, some of us like to avoid littering source directories with artifacts like node_modules. they make development environments stateful and unpredictable.

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

No branches or pull requests

5 participants