Skip to content

Commit 7697281

Browse files
authored
Fixed typo in Modules.md
The example tried to import `hello.js` from `hello.ts`. This page is missing sections on `package.json` and `tsconfig.json`. If you have these misconfigured then your modules won't work. Please add sections explaining what's needed. I'm not an expert on this, all I know is that `package.json` needs to have `"type": "module",` and `tsconfig.json` needs to have `"module": "ESNext",` and `"target": "ESNext"`. I'll start two sections at the bottom of the page, please complete these sections.
1 parent 8b07024 commit 7697281

File tree

1 file changed

+55
-1
lines changed
  • packages/documentation/copy/en/handbook-v2

1 file changed

+55
-1
lines changed

packages/documentation/copy/en/handbook-v2/Modules.md

+55-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export default function helloWorld() {
7272
}
7373
// @filename: index.ts
7474
// ---cut---
75-
import helloWorld from "./hello.js";
75+
import helloWorld from "./hello.ts";
7676
helloWorld();
7777
```
7878

@@ -404,3 +404,57 @@ You can see all of the available options and what their emitted JavaScript code
404404
## TypeScript namespaces
405405

406406
TypeScript has its own module format called `namespaces` which pre-dates the ES Modules standard. This syntax has a lot of useful features for creating complex definition files, and still sees active use [in DefinitelyTyped](/dt). While not deprecated, the majority of the features in namespaces exist in ES Modules and we recommend you use that to align with JavaScript's direction. You can learn more about namespaces in [the namespaces reference page](/docs/handbook/namespaces.html).
407+
408+
## package.json
409+
410+
To use modules your `package.json` must include `"type": "module",`. For example,
411+
412+
```js
413+
{
414+
"name": "functions",
415+
"type": "module",
416+
"scripts": {
417+
"build": "tsc",
418+
"build:watch": "tsc --watch",
419+
"serve": "npm run build && firebase emulators:start --only functions",
420+
"shell": "npm run build && firebase functions:shell",
421+
"start": "npm run shell",
422+
"deploy": "firebase deploy --only functions",
423+
"logs": "firebase functions:log"
424+
},
425+
"engines": {
426+
"node": "16"
427+
},
428+
"main": "src/index.ts",
429+
"dependencies": {
430+
"firebase-admin": "^10.2.0",
431+
"firebase-functions": "^3.21.0"
432+
},
433+
"devDependencies": {
434+
"typescript": "^4.6.4"
435+
},
436+
"private": true
437+
}
438+
```
439+
440+
## tsconfig.json
441+
442+
To use modules your `tsconfig.com` must have `"module": "ESNext",` and `"target": "ESNext"` in the `compilerOptions` section. `ESNext` isn't a version of JavaScript, rather, it means `the latest version of JavaScript`. For example,
443+
444+
```ts
445+
{
446+
"compilerOptions": {
447+
"module": "ESNext",
448+
"target": "ESNext",
449+
"strict": true,
450+
"noImplicitReturns": true,
451+
"noUnusedLocals": true,
452+
"outDir": "lib",
453+
"sourceMap": true
454+
},
455+
"compileOnSave": true,
456+
"include": [
457+
"src"
458+
]
459+
}
460+
```

0 commit comments

Comments
 (0)