typescript-eslint / typescript-eslint

:sparkles: Monorepo for all the tooling which enables ESLint to support TypeScript
https://typescript-eslint.io
Other
14.96k stars 2.69k forks source link

Docs: Quickstart guide should be clear on type: module not being a requirement #9094

Open moltco opened 2 months ago

moltco commented 2 months ago

Before You File a Documentation Request Please Confirm You Have Done The Following...

Suggested Changes

Improve the getting-started/Quickstart guide to mention that package.json must have "type":"module" otherwise the example will fail with import statement not being supported

Affected URL(s)

https://typescript-eslint.io/getting-started/

bradzacher commented 2 months ago

The reason we didn't specify this is because we treated it as assumed knowledge for using NodeJS. I.e. if you want to use ESM you need to have type: module in your package.json - as has been the way with ESM support in NodeJS since its release.

My question here would be - do we need to tell people the constraints of NodeJS? Or are we okay to assume that people know "if you don't use ESM then you must translate this to CJS".

cc @typescript-eslint/triage-team thoughts?


With the release of eslint 8.57.0 we could update this guide to use .mjs (prior to minor 57 - it was not supported by eslint).

auvred commented 2 months ago

Personally I'm +1 on recommending using .mjs config file with small note that it requires ESLint >= 8.57.0.

Also see the related conversation on Discord: https://discord.com/channels/1026804805894672454/1207049165079846962/1213212499713728553

kirkwaiblinger commented 2 months ago

+1 on calling out explicitly, and mentioning .mjs option.

molt2020 commented 2 months ago

I think it's important to mention +add external references.

A lot of people are just setting up the dev environment and may not be familiar with intricacies of the various stack options. Most how-to's start with do yarn add my-package so it's fair to point out anything that a noob will need.

Aim for bullet proof instructions for idiot users like me! 🙂

JoshuaKGoldberg commented 2 months ago

Yeah, we need to be very careful to note that it's not a requirement to use a module type.

ericmorand commented 2 months ago

@bradzacher this is not true:

I.e. if you want to use ESM you need to have type: module in your package.json

I understand that you mention the .mjs extension later in your post, but for the sake of correctness, I think you should update your comment to "I.e. if you want to execute a file ending by .js as ESM, one of the solution is to have type: module in your package.json".

A lot (and I mean a looooot) of people are convinced that the module declaration is mandatory to execute ESM modules. I think it is our duty to make it clear, as often as possible, that it is not.

the-sun-will-rise-tomorrow commented 1 month ago

The reason we didn't specify this is because we treated it as assumed knowledge for using NodeJS.

Hello. I'm just trying to write some Playwright tests. My goal is not to learn JavaScript or TypeScript or NodeJS, but is to just write tests.

Playwright documentation links to this project. When I tried to follow the setup instructions, I ran into this error.

I should note that I did not need to create package.json to write Playwright tests. That file was created by the commands from this project's documentation. I think that if that command is going to create a file, it might as well create it in a way that allows this project to work correctly. Refusing to even mention this in the documentation seems like a really strange decision to me!

By the way, for NodeJS dummies like me, the solution is to add this line to package.json:

--- a/test/package.json
+++ b/test/package.json
@@ -1,4 +1,5 @@
 {
+  "type": "module",
   "devDependencies": {
     "@eslint/js": "^9.4.0",
     "@types/eslint__js": "^8.42.3",