admin管理员组

文章数量:1313786

`"C:\Program Files\nodejs\node.exe" C:\Users\Keith\WebstormProjects\flashbot\src\index.ts
internal/process/esm_loader.js:74
    internalBinding('errors').triggerUncaughtException(
                              ^
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for C:\Users\Keith\WebstormProjects\flashbot\src\in
dex.ts
←[90m    at Loader.defaultGetFormat [as _getFormat] (internal/modules/esm/get_format.js:71:15)←[39m
←[90m    at Loader.getFormat (internal/modules/esm/loader.js:105:42)←[39m
←[90m    at Loader.getModuleJob (internal/modules/esm/loader.js:243:31)←[39m
←[90m    at async Loader.import (internal/modules/esm/loader.js:177:17)←[39m
←[90m    at async Object.loadESM (internal/process/esm_loader.js:68:5)←[39m {
  code: ←[32m'ERR_UNKNOWN_FILE_EXTENSION'←[39m
}
Process finished with exit code 1`

There is a lot of code and files for this project so I'm not sure what to tweak. It does, however, exist on github - if you think you know the solution.

`"C:\Program Files\nodejs\node.exe" C:\Users\Keith\WebstormProjects\flashbot\src\index.ts
internal/process/esm_loader.js:74
    internalBinding('errors').triggerUncaughtException(
                              ^
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for C:\Users\Keith\WebstormProjects\flashbot\src\in
dex.ts
←[90m    at Loader.defaultGetFormat [as _getFormat] (internal/modules/esm/get_format.js:71:15)←[39m
←[90m    at Loader.getFormat (internal/modules/esm/loader.js:105:42)←[39m
←[90m    at Loader.getModuleJob (internal/modules/esm/loader.js:243:31)←[39m
←[90m    at async Loader.import (internal/modules/esm/loader.js:177:17)←[39m
←[90m    at async Object.loadESM (internal/process/esm_loader.js:68:5)←[39m {
  code: ←[32m'ERR_UNKNOWN_FILE_EXTENSION'←[39m
}
Process finished with exit code 1`

There is a lot of code and files for this project so I'm not sure what to tweak. It does, however, exist on github - https://github./flashbots/searcher-minter if you think you know the solution.

Share Improve this question asked Sep 21, 2021 at 0:20 M SM S 311 silver badge2 bronze badges 2
  • 1 node doesn't know how to run typescript – Bravo Commented Sep 21, 2021 at 0:39
  • .ts extensions are for typescript files. I think you might need to re-check if typescript is enabled in that project. Or if you have already run yarn install or npm install before running the project. – catzilla Commented Sep 28, 2021 at 12:06
Add a ment  | 

2 Answers 2

Reset to default 6

You can't run the Typescript code by passing it to Node.js directly, Node.js doesn't provide native support for executing Typescript. The code has to be either piled on-the-fly or prepiled. here are some recipes:

  • To run a selected TypeScript file using ts-node:

    • Install ts-node using npm i ts-node.
    • Create a new Node.js run/debug configuration.
    • Add --require ts-node/register to the Node parameters field.
    • In the JavaScript file field add $FilePathRelativeToProjectRoot$.
    • Save configuration.
    • Use it to run (or debug) a file that is currently opened in the editor or selected in the Project view. You can do that using the icons on the navigation bar or Run... action.

If you need to pass any additional parameters to ts-node (e.g. --project tsconfig.json), you can add them to the Application parameters field in the run/debug configuration.

  • To pile app with TypeScript and run a selected TypeScript file

    • Create a Node.js run/debug configuration.
    • In the Before Launch section, click Add and select Compile TypeScript.
      • Select tsconfig.json.
      • In the JavaScript file field you need to select the path to the piled .js file.
      • If a piled JavaScript lives next to its source, add $FileRelativeDir$/$FileNameWithoutExtension$.js
      • If files are saved in an output folder (preserving the folder structure), add the folder name before the pattern, e.g. build/$FileRelativeDir$/$FileNameWithoutExtension$.js
      • Save configuration.
      • Use it to run (or debug) a file that is currently opened in the editor or selected in the Project view.

I think you should adjust your tsconfig.json file and add a new start script, I think maybe the global script you trying to run can't find the ts-node module

{
  "pilerOptions": {
    "target": "ES2018",
    "module": "monjs",
    "lib": [
      "es2018"
    ],
    "declaration": true,
    "strict": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "noImplicitThis": true,
    "alwaysStrict": true,
    "noUnusedLocals": false,
    "noUnusedParameters": false,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": false,
    "inlineSourceMap": true,
    "inlineSources": true,
    "experimentalDecorators": true,
    "strictPropertyInitialization": false,
    "typeRoots": [
      "./node_modules/@types"
    ]
  },
  "exclude": [
    "node_modules",
  ]
}

###Add new start in your package.json

  "scripts": {
    "start": "npx ts-node src/index.ts"
  },

本文标签: javascriptHaving errorkeeps saying Unknown File ExtensionStack Overflow