kentcdodds / cross-env

🔀 Cross platform setting of environment scripts

Home Page:https://www.npmjs.com/package/cross-env

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

/bin/sh: cross-env: command not found

raed667 opened this issue · comments

commented
  • cross-env version: 5.1.4
  • node version: 8.9.3
  • yarn version: 1.3.2

Relevant code or config

    "scripts": {
    "start":
      "cross-env REACT_APP_VERSION=$npm_package_version react-app-rewired start"
 }

What you did:

Run cross-env inside a docker

What happened:

Start webpack dev server ...
yarn run v1.3.2
$ cross-env REACT_APP_VERSION=$npm_package_version react-app-rewired start
/bin/sh: cross-env: command not found
error Command failed with exit code 127.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Problem description:
Sometimes (randomly i think) cross-env is not found when starting a docker and running yarn

Suggested solution:

Had same issue, is not working when running inside a docker container.

edit:

Works with an image I build locally but not when I build it on Circleci 🤔

commented

@cesarvarela I think its an issue with "open folders" between the host and the docker. Forcing the close of those files (every time i run) seems to fix this. But its not a solution since you can't do this in an evironment where you don't have access to the host.

same to u guys

try to use a full path

./node_modules/.bin/cross-env CUSTOMER_NAME=CCC
./node_modules/.bin/cross-env-shell CUSTOMER_NAME=CCC

My guess, you have your NODE_ENV set to production on CI and cross-env is in your devDependencies. So when CI installs your dependencies, it only installs dependencies and not devDependencies because that's how npm works when the NODE_ENV is set to production.

The solution: Don't see the NODE_ENV to production on CI.

Leaving this here because I faced something similar:

You have to mount your node_modules directory as a volume inside your docker-compose.yml file or your Dockerfile (my case was docker compose but there's probably similar syntax)

I had to add the last line in this snippet, to mount the node_modules and have access to local dependencies

server:
    build: ./server
    image: app
    expose:
      - 3001
    ports:
      - 3001:3001
    volumes:
      - ./server:/srv/app
      - /srv/app/node_modules

Leaving this here because I faced something similar:

You have to mount your node_modules directory as a volume inside your docker-compose.yml file or your Dockerfile (my case was docker compose but there's probably similar syntax)

I had to add the last line in this snippet, to mount the node_modules and have access to local dependencies

server:
    build: ./server
    image: app
    expose:
      - 3001
    ports:
      - 3001:3001
    volumes:
      - ./server:/srv/app
      - /srv/app/node_modules

thanks you, it works for me

My guess, you have your NODE_ENV set to production on CI and cross-env is in your devDependencies. So when CI installs your dependencies, it only installs dependencies and not devDependencies because that's how npm works when the NODE_ENV is set to production.

The solution: Don't see the NODE_ENV to production on CI.

it works for me. Thank you :)

I'd love to get some more guidance on this one. We're seeing this error on with docker-compose on a Windows host, but not on OS X or Linux hosts.

    // package.json
    "env:dev": "cross-env NODE_ENV=development",
    "env:prod": "cross-env NODE_ENV=production",
    "dev-docker": "npm run env:dev -- webpack-dev-server --host 0.0.0.0",

The ENTRYPOINT is npm run dev-docker

Same issue here when running postinstall script

Sorry for not responding to this earlier. It's been long enough that I'm going to close this issue. If you're still experiencing problems, please open a new issue.

Sorry... I have installed cross-env to dependencies but the error is not missing...
Unless I set ./node_modules/.bin/cross-env

On my PC that ok, but in jenkins will be get error

Instead of setting your NODE_ENV away from production, another option is to perform a yarn install with the production=false flag (this tells yarn to install both production and dev dependencies):

yarn install --production=false

https://classic.yarnpkg.com/en/docs/cli/install/#toc-yarn-install-production-true-false

In arm64 ?
npm install cross-env will fix your problems!