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

Ability to specify version of Node in server templates #1469

Closed
nmoinvaz opened this issue Jan 15, 2019 · 15 comments
Closed

Ability to specify version of Node in server templates #1469

nmoinvaz opened this issue Jan 15, 2019 · 15 comments

Comments

@nmoinvaz
Copy link

nmoinvaz commented Jan 15, 2019

This issue is a feature for the ability to specify the version of Node used on the server template. Currently, it only uses version 8.14.0 which is missing some important features.

I'm not quite sure. I believe packages.json supports the use of "engines". But some other method would be acceptable too.

@nmoinvaz
Copy link
Author

nmoinvaz commented Jan 15, 2019

I think this might be supported through dependencies in package.json:

  "dependencies": {
    "node": "11.6.0",
    "npm": "6.5.0"
  },

The sandbox probably wasn't reloaded properly after adding the dependency. Closing.

@riongull
Copy link

riongull commented May 27, 2020

If anyone is here trying to figure out how to change the version of Node used in the server container feature of codesandbox.io, unfortunately you can't according to this response.

You can't change the node version at this time. (Jan 7, 2020)

@garethx
Copy link
Contributor

garethx commented May 27, 2020

The node as a dependency workaround does work though: https://codesandbox.io/docs/faqs#can-i-change-the-node-version-used-in-a-container-sandbox

I've updated my response in the linked thread.

@riongull
Copy link

Thanks for the quick reply, and link to the documentation, @garethx. That worked for me.

For the lazy, just do update your package.json to include:

"scripts": {
  "start": "./node_modules/node/node_modules/.bin/node ./src/index.js"
},
"dependencies": {
  "node": "14.3.0"
},

Click the link @garethx shared above to see usage with nodemon.

Now we just need Google to return the docs page above this issue when searching for how to "change node version in codesandbox" :)

@jagreehal
Copy link

The link to the documentation has changed it should be https://codesandbox.io/docs/start#can-i-change-the-node-version-used-in-a-container-sandbox

The solution is set the node property in sandbox.config.json

{
  "node": 14
}

@marcandrews
Copy link

marcandrews commented Dec 31, 2020

This still isn't working for me in this Sandbox https://codesandbox.io/s/twitch-js-typescript-example-tnnys?file=/sandbox.config.json

sandbox.config.json:

{
  "infiniteLoopProtection": true,
  "hardReloadOnChange": false,
  "template": "node",
  "view": "terminal",
  "container": {
    "node": "12"
  },
  "node": "12"
}

A dependency has { "engines": { "node": ">12" } } and I'm getting the following error when I run the sandbox:

error twitch-js@2.0.0-beta.41: The engine "node" is incompatible with this module. Expected version ">=12". Got "10.23.0"

I can open a new terminal and switch to Node 12 with nvm and run the code just fine though.

Any ideas?

Edit:

Node 14 works 🤔

@lbogdan
Copy link
Contributor

lbogdan commented Jan 6, 2021

Hey @marcandrews ,

For me it works with both node 12 and 14 in a fork of your original sandbox:

image

Might be that you didn't restart the container after you changed the version in sandbox.config.json?

@marcandrews
Copy link

@lbogdan, I was having a lot of issues in general with Codesandbox that day, but they all seemed to be resolved the next day.

Thanks for following up ❤️

@slorber
Copy link

slorber commented Apr 5, 2021

Hey!

Was just wondering if anyone can explain the difference between node and container.node? Reading the doc it's not really clear to me which one I want to set.

@lbogdan
Copy link
Contributor

lbogdan commented Apr 7, 2021

Hey @slorber ,

It's container.node. I agree that from the docs it's not obvious that port, startScript and node are under container, we should probably make that clearer.

@slorber
Copy link

slorber commented Apr 7, 2021

@lbogdan actually the most confusing is that "node" is documented as "node" and also inside "container" (as "node"):

image

Maybe just removing the top-level node would make this less confusing?

@ghost
Copy link

ghost commented Apr 4, 2022

The node as a dependency workaround does work though: https://codesandbox.io/docs/faqs#can-i-change-the-node-version-used-in-a-container-sandbox

I've updated my response in the linked thread.

Links dead m8 @garethx

@sairion
Copy link

sairion commented Mar 12, 2023

For future ref, the docs link is moved to: https://codesandbox.io/docs/learn/sandboxes/configuration#sandbox-configuration

@ShaMan123
Copy link

I can confirm that adding .codesandbox/Dockerfile is all that is needed to make it work:

FROM node:18

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

No branches or pull requests

9 participants