Env: node: No such file or directory when using netlify-cli

Hi,

I am successfully running my project in development with netlify dev.
However my friend also jumped on the project and can’t start the project.
The error is env: node: No such file or directory
I understand it starts to run the command = "npm start" from the netlify.toml

He can run npm scripts manually without a problem, it’s only when the netlify-cli tries to run the command.

I tried completely uninstalling node and npm, then installed nvm and npm with Homebrew.
I thought a pointer to the node folder somewhere was wrong and this should reset it, start from a clean slate. But still, netlify-cli can’t run the npm start command.

Anybody has an idea ?

Thanks a lot!

Peter

Hi Peter, we’ve just run into the same problem. We haven’t found a real solution yet, but it seems this is because of different minor versions of the CLI.

It runs fine with netlify-cli/2.40.0 but exhibits strange behaviour with netlify-cli/2.46.0.

Running npm uninstall -g netlify-cli then npm install -g netlify-cli@2.40.0 fixes the problem temporarily

1 Like

Hey @peterDijk and @seb, thank you for reporting this issue. This is a recognized problem. Basically, the node command is not getting the correct PATH variable in this case.
There’s a PR to fix this, please hold on until we release it.

Awesome! Thanks so much for quick response!

@peterDijk if you can, please try cloning the https://github.com/netlify/cli/tree/raees/framework-option branch, link it via npm link and see if that fixes the issue.
So that, we can make sure that it works for your problem.

Hi Raees,

We did that, and the node issue is solved, the proxy server starts.

Only, it doesn’t read the netlify.toml that is definitely there. npm start runs the dev server OK.

This is the output of netlify dev :

◈ Netlify Dev ◈
◈ Overriding the following env variables with .env file: API_URL,GT_API,SEARCH_PROFILE_API,SEARCH_PROFILE_API_EXT
◈ No dev server detected, using simple static server
◈ Using current working directory
◈ Unable to determine public folder to serve files from.
◈ Setup a netlify.toml file with a [dev] section to specify your dev server settings.
◈ See docs at: [https://github.com/netlify/cli/blob/master/docs/netlify-dev.md#project-detection](https://github.com/netlify/cli/blob/master/docs/netlify-dev.md#project-detection)
◈ Using current working directory for now...
◈ Function builder netlify-lambda detected: Running npm script build:lambda
 ›  Warning: ◈ This is a beta feature, please give us feedback on how to improve at [https://github.com/netlify/cli/](https://github.com/netlify/cli/)
◈ Server listening to 3000
Waiting for localhost:3000.
◈ Functions server is listening on 34567
Connected!
Waiting for localhost:34567.
Connected!

netlify.toml:

[build]
  command = "npm run build"
  functions = "functions" 
  publish = "dist"

[dev]
  command = "npm start"
  functions = "functions" 
  publish = "dist"
  port=8000 # destination port to use in browser. Lambda dev server is started on same port
  targetPort=3000 # port that local rollup server is running on

[[redirects]]
  from = "/*"
  to = "/index.html"
  status = 200

Thank you @peterDijk for testing this locally. Your feedback helped us fix at least two bugs. I’ve added new tests to make sure there’s no regression.

Nice!!

Glad that I could help.

Anytime for Netlify, let me know if I can help another time

1 Like

Any idea when the fix will be released?

netlify-cli@2.47.0 has just been released. Please update and let us know if that fixes your problem.

1 Like

Thanks so much for the quick release. Still working to confirm that my own issues were fixed (or just the fault of my own build) but already seeing nice changes.

One thing I did notice though is that if port and serverPort have the same values the CLI throws this error on start:

Error: “port” and “targetPort” options cannot have same values. Please consult the documentation for more details: https://cli.netlify.com/netlify-dev#netlifytoml-dev-block

But then if you go to that URL the docs show port and serverPort sharing the same values:

[dev]
  command = "yarn start" # Command to start your dev server
  port = 3000 # Port that the dev server will be listening on
  targetPort = 3000 # Port of target app server

Yall may want to update that too.

Ah Thanks for pointing that out @bradleygriffith. Fixed now!

@raeesbhatti could you maybe help me understand how Im supposed to make the port, targetPort, proxyPort work with webpack-dev-server?

My webpack-dev-server runs on port 8080. In my netlify.toml Ive tried tons of variations of configuration to no avail. No matter what I do it seems that the webpack-dev-server runs on the expected port, 8080, but that the path/port netlify dev server runs on and opens just renders a blank page. Furthermore, if I inspect the blank page it’s just empty HTML unless I shift+reload (have to do this every time) and then I can see that the correct base HTML is rendered, but then the bundled app JavaScript on the page is also empty. If i change the port manually in the browser to the webpack-dev-server one, it shows the correct bundled JavaScript. What am I doing wrong?

[dev]
  command = "npm run dev" # Command to start your dev server
  port = 8888 # The port for the main Netlify Dev server, the one you'll open in browser.
  targetPort = 8080 # The port for your application server or site generator.
  #proxyPort = 8080
  functionsPort = 9000
  publish = "public/dist/" # If you use a _redirect file, provide the path to your static content folder
  autoLaunch = true # a Boolean value that determines if Netlify Dev launches the local server address in your browser


# The following redirect is intended for use with most SPAs that handle
# routing internally.
[[redirects]]
  from = "/*"
  to = "/app.html"
  status = 200
  force = true

It seems that maybe webpack redirects conflict with netlify redirects. If I keep my redirects in my webpack-dev-server configuration and remove them from my netlify.toml file everything works fine, but I think this wont work on actual production…

webpack config:

module.exports = merge(common, {
  mode: "development",
  devServer: {
    contentBase: path.resolve(__dirname, "public/dist"),
    port: 8080,
    publicPath: "/",
    historyApiFallback: {
      rewrites: [
        {
          from: /\//,
          to: "/app.html"
        }
      ]
    }
  }
});

Ok Ive got it sort of working. I had to move all of my assets (bundled or otherwise) that I want served into a separate path to be served from a directory, /static. In my earlier setup I wanted assets served from the same endpoint as other routes, e.g.; http://my-site.com/my-image.png to http://my-site.com/static/my-image.png.

With that change in place, I updated all of my webpack config and netlify config to say that the public path was now /static and not /, and then added this to my netlify.toml redirects:

# Hack. Prevents our catch-all `app` entrypoint for paths to root, `/*` content
# from redirecting static assets like scripts or images.
[[redirects]]
  from = "/static/*"
  to = "/static/:splat"
  status = 200
  force = true

Above the normal:

# Handle redirect to main `app` entrypoint for paths to any root, `/*`, content.
[[redirects]]
  from = "/*"
  to = "/static/app.html"
  status = 200
  force = true

This is a hack from this thread: Redirect whole site to subfolder except static assets like CSS/JS - #4 by fool

I still have the issue where I must hard-reload (cmd+shift+r) to actually see any content though…

@bradleygriffith Can you please go through the conversation here Redirects tag in netlify.toml causes bundle error · Issue #827 · netlify/cli · GitHub and try the solutions. I’m sure it will fix your problem.

Hi Raees,
Unfortunately, v 2.47 introduces another issue. I have the same on my laptop now, where 2.46 was working fine.
The output from the netlify dev command is:
◈ Netlify Dev ◈
◈ Overriding the following env variables with .env file: API_URL,GT_API,SEARCH_PROFILE_API,SEARCH_PROFILE_API_EXT
◈ No app server detected, using simple static server
◈ Starting Netlify Dev with custom config

The **No app server detected, using simple static server** is new.
And makes my app not work on port 8000 anymore
console error: Uncaught SyntaxError: Unexpected token '<' , the app.bundle.js contains html of the index ?

version 2.40 works OK

hey Peter,

thanks for letting us know about that! we are finishing up some work on Dev and have a PR in the pipeline that should definitely fix this issue for you. keep an eye on it here: