Answer the question
In order to leave comments, you need to log in
How to fix this nodejs, typescript error?
In order: 1. Downloaded this repository as a
zip archive .
2. Unzipped, uploaded the files to the server, executed in the /root/autoinst directory .
3. Being in the directory /root/autoinst executed
I got an error:npm i
node examples/upload-story.example.ts
(node:28667) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
/root/autoinst/examples/upload-story.example.ts:1
import { IgApiClient } from '../src';
^^^^^^
SyntaxError: Cannot use import statement outside a module
at wrapSafe (internal/modules/cjs/loader.js:1063:16)
at Module._compile (internal/modules/cjs/loader.js:1111:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1167:10)
at Module.load (internal/modules/cjs/loader.js:996:32)
at Function.Module._load (internal/modules/cjs/loader.js:896:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47
"type": "module"
(node:28759) ExperimentalWarning: The ESM module loader is experimental.
internal/modules/run_main.js:54
internalBinding('errors').triggerUncaughtException(
^
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /root/autoinst/examples/upload-story.example.ts
at Loader.defaultGetFormat [as _getFormat] (internal/modules/esm/get_format.js:65:15)
at Loader.getFormat (internal/modules/esm/loader.js:110:42)
at Loader.getModuleJob (internal/modules/esm/loader.js:241:31)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async Loader.import (internal/modules/esm/loader.js:175:17) {
code: 'ERR_UNKNOWN_FILE_EXTENSION'
}
Answer the question
In order to leave comments, you need to log in
The node does not know how to typescript
Option 1: compile
install: npm i typescript
and run $(npm bin)/tsc examples
naturally need tsconfig.json
Option 2: ts-node
install: npm i typescript ts-node
and run
$(npm bin)/ts-node examples/upload-story.example.ts
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question