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

[BUG] 10.5.2 regresses running scripts from workspaces in certain Dockerfiles with error No workspaces found #7413

Open
2 tasks done
jAg-upfort opened this issue Apr 24, 2024 · 2 comments
Assignees
Labels
Bug thing that needs fixing Priority 2 secondary priority issue Release 10.x

Comments

@jAg-upfort
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

This issue exists in the latest npm version

  • I am using the latest npm

Current Behavior

npm as of version 10.5.2 no longer lets you run scripts in a workspace package.json if your project is located at /. I've confirmed it worked in 10.5.1.
image

the specific error is

 > [6/7] RUN npm run -w packages/workspace build:                                                                                                                                                                   
2.156 npm ERR! No workspaces found:
2.157 npm ERR!   --workspace=packages/workspace
2.161 
2.161 npm ERR! A complete log of this run can be found in: /root/.npm/_logs/2024-04-24T18_23_18_824Z-debug-0.log
------
Dockerfile.txt:14
--------------------
  12 |     RUN npm install -g npm@$NPM_VERSION
  13 |     
  14 | >>> RUN npm run -w packages/workspace build
  15 |     
  16 |     ENTRYPOINT ["bash"]
--------------------
ERROR: failed to solve: process "/bin/sh -c npm run -w packages/workspace build" did not complete successfully: exit code: 1

I've included a zipped project, the 4 individual files and a screenshot of the project with all the files in their entirety visible. The top level package.json has scripts to build the dockerfile in ways that show the bug and that it's a regression.

image

npm-bug-example.zip

package.json
Dockerfile.txt
package-lock.json
package.json

Expected Behavior

The Dockerfile should build, and not fail due to being unable to find the workspace. This works successfully in 10.5.1, but does not work in 10.5.2

Steps To Reproduce

Both validations assume the project has been unzipped from the uploaded archive or recreated with the raw files in the right places, that docker is installed, and that the testing environment has an internet connection for downloading the base docker images.

I have personally only run this on an Ubuntu system, so Windows or mac users might have other setup requirements.

To validate the issue:

  1. run npm run npm-bad

To validate that things work in 10.5.1:

  1. run npm run npm-good

Environment

  • npm: 10.5.2
  • Node.js: node 18 or 20 will hit this issue. I didn't test any other releases
  • OS Name: whatever the node:iron and node:hydrogen dockerfiles use, but i've also recreated the issue with ubuntu:jammy and postgres:15-bullseye for shiggles as part of debugging the issue in my actual environment
  • System Model Name: ?
  • npm config:
#10 [6/8] RUN npm config ls
#10 2.477 ; node bin location = /usr/local/bin/node
#10 2.477 ; node version = v20.12.2
#10 2.477 ; npm local prefix = /
#10 2.477 ; npm version = 10.5.2
#10 2.477 ; cwd = /
#10 2.477 ; HOME = /root
#10 2.477 ; Run `npm config ls -l` to show all defaults.
#10 DONE 2.6s
@jAg-upfort jAg-upfort added Bug thing that needs fixing Needs Triage needs review for next steps Release 10.x labels Apr 24, 2024
@milaninfy milaninfy added Priority 2 secondary priority issue and removed Needs Triage needs review for next steps labels Apr 30, 2024
@jAg-upfort
Copy link
Author

This issue exists in the latest npm version

  • I am using the latest npm

Expected Behavior

The Dockerfile should build, and not fail due to being unable to find the workspace. This works successfully in 10.5.1, but does not work in 10.5.2

This issue also exists in 10.6.0 and 10.7.0

@reggi reggi self-assigned this May 3, 2024
@reggi
Copy link
Contributor

reggi commented May 3, 2024

First off special thanks to @jAg-upfort for documenting this bug so well with an example 🤘 🏆

  • We knew that 10.5.1 worked and 10.5.2 did not.
  • I noticed that running the workflow on my mac worked in both versions, only docker failed
  • I noticed that when I changed the docker WORKDIR to /app and copied both of the package.json in under that directory it worked in docker, so something was wrong with running workflows in the root directory /. This is impossible to test on mac, because root is readonly.

I created a docker file so I could ssh into a linux environment:

SSHable docker node 20 instance
# Use an official Node.js runtime as the base image
FROM node:20

# Install OpenSSH server
RUN apt-get update && apt-get install -y openssh-server

# Set root password
RUN mkdir /var/run/sshd \
    && echo 'root:root' | chpasswd \
    && useradd -m test \
    && passwd -d test \
    && sed -i'' -e's/^#PermitRootLogin prohibit-password$/PermitRootLogin yes/' /etc/ssh/sshd_config \
    && sed -i'' -e's/^#PasswordAuthentication yes$/PasswordAuthentication yes/' /etc/ssh/sshd_config \
    && sed -i'' -e's/^#PermitEmptyPasswords no$/PermitEmptyPasswords yes/' /etc/ssh/sshd_config \
    && sed -i'' -e's/^UsePAM yes/UsePAM no/' /etc/ssh/sshd_config

# Install NVM
ENV NVM_DIR /root/.nvm

RUN curl https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash \
    && . $NVM_DIR/nvm.sh \
    && nvm install $NODE_VERSION \
    && nvm alias default $NODE_VERSION \
    && nvm use default

ENV NODE_PATH $NVM_DIR/v$NODE_VERSION/lib/node_modules
ENV PATH      $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH

COPY example/package.json /package.json
COPY example/packages/alpha/package.json /packages/alpha/package.json

# Expose port 22 for SSH access
EXPOSE 22

# Start SSH server
CMD ["/usr/sbin/sshd", "-D"]
Script to control docker kill / build / run / ssh
if [[ "$1" == "kill" ]]; then
    docker stop $(docker ps -q)  
    exit 0
elif [[ "$1" == "build" ]]; then
    docker build --progress=plain -t npm-ssh -f ./Dockerfile.ssh .
    exit 0
elif [[ "$1" == "run" ]]; then
    docker run -v ./cli:/cli -d -p 2222:22 npm-ssh
    exit 0
elif [[ "$1" == "ssh" ]]; then
    ssh root@localhost -p 2222
fi

I copied /package.json and /packages/alpha/package.json to the root of the container, and within the /root user dir to have two places to try the workflow.

Then I cloned the cli so we can add it as a volume in docker.

git clone git@github.com:npm/cli.git && cd cli && node scripts/resetdeps.js && ./bin/npm-cli.js

I checked out 10.5.1:

git checkout tags/v10.5.1

This got docker into a state where I could run the npm cli and edit the runtime locally.

/cli/bin/npm-cli.js run --workspace=packages/alpha build 

Because 10.5.1 works, all I needed to do now was tick up each commit from here and wait for it to break:

git checkout `git rev-list --topo-order HEAD..origin/latest | tail -1`

And 🎉💥 the offending commit deps: @npmcli/map-workspaces@3.0.6

Package Repo: https://github.com/npm/map-workspaces
Commit: 699a1de

Knowing what we knew about the issue being tied to the root directory. I could litter that file with console.logs, run it in / and /root/example and see what the differences were.

It turns out that

  • When cwd is / matches is [ '/packages/alpha' ]
  • When cwd is /root/example matches is [ 'packages/alpha' ]

This would seem to be an inconsistency with the glob package when matching at root /.

A simple fix on our end would be to remove the proceeding slash npm/map-workspaces#149

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Priority 2 secondary priority issue Release 10.x
Projects
None yet
Development

No branches or pull requests

3 participants