You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Copy file name to clipboardExpand all lines: packages/documentation/copy/en/handbook-v2/Modules.md
+55-1
Original file line number
Diff line number
Diff line change
@@ -72,7 +72,7 @@ export default function helloWorld() {
72
72
}
73
73
// @filename: index.ts
74
74
// ---cut---
75
-
importhelloWorldfrom"./hello.js";
75
+
importhelloWorldfrom"./hello.ts";
76
76
helloWorld();
77
77
```
78
78
@@ -404,3 +404,57 @@ You can see all of the available options and what their emitted JavaScript code
404
404
## TypeScript namespaces
405
405
406
406
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,
0 commit comments