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

My code will not run after importing ms #167

Closed
KNCI-Github opened this issue Sep 17, 2021 · 15 comments
Closed

My code will not run after importing ms #167

KNCI-Github opened this issue Sep 17, 2021 · 15 comments

Comments

@KNCI-Github
Copy link

Since installing ms with npm, I get the following error:

node main.js
/home/runner/RamenBot/node_modules/ms/dist/index.cjs:16
return options?.long ? fmtLong(value) : fmtShort(value);
^

SyntaxError: Unexpected token '.'
at wrapSafe (internal/modules/cjs/loader.js:915:16)
at Module._compile (internal/modules/cjs/loader.js:963:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Module.require (internal/modules/cjs/loader.js:887:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object. (/home/runner/RamenBot/commands/mute.js:1:12)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
exit status 1

(This is on repl.it btw, for some reason it works on vsc but not repl.it, it also won't run on heroku either)

@Sikksens
Copy link

Sikksens commented Sep 20, 2021

having the same issue on Repl.it, did you manage to sort it out by any chance?

Update: Looks like I just had to upgrade the version of Node running on Repl.it as the default is v12

@leerob
Copy link
Member

leerob commented Sep 20, 2021

Does Repl.it require ESM code? I see an error about about CJS. If so, could you try the latest canary which ships support for ES Modules?

https://github.com/vercel/ms/releases/tag/3.0.0-canary.1

@marcuspoehls
Copy link

I’m using ms@3.0.0-canary.1 and run into the same issue in CJS code. The exported CJS code of ms is using optional chanining which is incompatible with Node.js 12. You must at least use Node.js v14 or later.

I guess v3 of this package uses Typescript and should be able to transpile the code being compatible with Node.js v12. I just don’t know enough about the build/transpilation process yet to make a suggestions how the current setup needs to be modified to work with Node.js v12.

@marcuspoehls
Copy link

marcuspoehls commented Sep 21, 2021

I digged through the scripts/build.js file searching the transpilation step causing this issue. It’s this part:

ms/scripts/build.js

Lines 23 to 26 in 1304f15

compile([sourceFile], {
module: ts.ModuleKind.ES2020,
declaration: true,
});

The snippet explicitly referencing ES2020 (Node.js v14).

Using ES2019 resolves to Node.js v12 and would map the engine requirement in the package.json file.

@leerob
Copy link
Member

leerob commented Sep 21, 2021

Ah yes, with 3.0 we will be dropping support for Node 12, since it's deprecated 👍

https://nodejs.org/en/about/releases/

@leerob
Copy link
Member

leerob commented Sep 21, 2021

But the non-canary release should still be working with Node 12 (latest stable).

@marcuspoehls
Copy link

@leerob Ok thank you! Node 12 is in maintenance LTS until 2022-04-30. I hoped you would support it in 3.0 as well 😃

@leerob
Copy link
Member

leerob commented Sep 21, 2021

Good point - we will chat about that before it becomes stable 😄

@marcuspoehls
Copy link

Sweet! Thank you!

@mrmckeb
Copy link
Contributor

mrmckeb commented Sep 28, 2021

Just to be clear @marcuspoehls, the only major change here is ESM and native types. So you shouldn't need to update, however I understand your point... and as it's probably an easy change, maybe we should add back in Node 12 support until LTS ends.

@marcuspoehls
Copy link

@mrmckeb Hey Brody, the native types are the reason I wanted to update 😃 you have a nice typing setup (with template strings) making things just a bit nicer when using typescript.

I downgraded to ms@2.x and created my own typings. I’ll probably upgrade to ms@3.x next year when Node.js 12 is EOL. Assuming that you're targeting Node.js v14 with 3.x

@polRk
Copy link

polRk commented Nov 4, 2021

Ah yes, with 3.0 we will be dropping support for Node 12, since it's deprecated 👍

Why?

since it is outdated

It's a terrible decision, since you may well support version 6

@Uzlopak
Copy link

Uzlopak commented Jan 17, 2022

Use @lukeed/ms instead of this package.

@leerob
Copy link
Member

leerob commented Jan 18, 2022

I agree with @mrmckeb, might make sense to wait until April to get rid of Node 12. Appreciate the feedback here!

@leerob
Copy link
Member

leerob commented Jul 11, 2022

I believe we can close this out now. We are planning for the 3.0 stable release, which will include dropping Node 12 support since the LTS has passed. You can track that here: #184

@leerob leerob closed this as completed Jul 11, 2022
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

7 participants