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

web-ext: build with NODE_ENV=production #256175

Closed
wants to merge 2 commits into from

Conversation

wingdeans
Copy link

Description of changes

Fixes #256174

Setting NODE_ENV as an attribute results in this error:

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'shelljs' imported from /build/source/scripts/bu>

Instead it is set in the preBuild hook, just before it is needed.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 23.11 Release Notes (or backporting 23.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

@NixOSInfra NixOSInfra added the 12. first-time contribution This PR is the author's first one; please be gentle! label Sep 19, 2023
@dotlambda
Copy link
Member

@wingdeans Do you want to add yourself as maintainer?

@wingdeans
Copy link
Author

Setting NODE_ENV as an attribute results in this error:

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'shelljs' imported from /build/source/scripts/bu>

Apparently this was because npm ci doesn't install devDependencies when NODE_ENV is set to production.

Using --include=dev in conjunction with NODE_ENV works and seems cleaner:

NODE_ENV = "production";
npmInstallFlags = "--include=dev";

@wingdeans Do you want to add yourself as maintainer?

No thanks

@lilyinstarlight
Copy link
Member

lilyinstarlight commented Oct 5, 2023

I wonder if we should instead be using --omit=dev on the npmBuildHook so that way the build script is always run with NODE_ENV=production implicitly? (edit: perhaps that's too unintuitive... maybe just doing export NODE_ENV=production explicitly at the end of the configure hook is as better idea)

@lilyinstarlight
Copy link
Member

I'm thinking of something like this:

diff --git a/pkgs/build-support/node/build-npm-package/hooks/npm-config-hook.sh b/pkgs/build-support/node/build-npm-package/hooks/npm-config-hook.sh
index 486b0c2f8372df..1936c32b6c07dd 100644
--- a/pkgs/build-support/node/build-npm-package/hooks/npm-config-hook.sh
+++ b/pkgs/build-support/node/build-npm-package/hooks/npm-config-hook.sh
@@ -109,6 +109,9 @@ npmConfigHook() {
     rm "$CACHE_MAP_PATH"
     unset CACHE_MAP_PATH
 
+    # Set build NODE_ENV to "production" by default *after* `npm ci` and `npm rebuild` to avoid an implicit `--omit=dev`
+    export NODE_ENV="${NODE_ENV-production}"
+
     if [ -n "${npmRoot-}" ]; then
       popd
     fi

I'll do some testing and possibly open that as a PR to fix the underlying issue. Feel free to take that diff for this PR, though, since you came up with the idea and I'm not attached to attribution

@jocelynthode
Copy link
Contributor

Hey, any update on this PR? problem is unfortunately still there :(

@kirillrdy
Copy link
Member

as per my comment in #256174 I think the issue has been resolved

@wingdeans
Copy link
Author

Confirmed fixed

@wingdeans wingdeans closed this Dec 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

web-ext fails to start
6 participants