vercel / ms

Tiny millisecond conversion utility

Home Page:https://npmjs.com/ms

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

My code will not run after importing ms

KNCI-Github opened this issue · comments

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)

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

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

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.

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.

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

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

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

@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 😃

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

Sweet! Thank you!

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.

@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

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

Use @lukeed/ms instead of this package.

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

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