当我尝试在 Heroku 上启动我的应用程序时,我得到了以下堆栈跟踪。它只是一个基本的 ts.app,就像您在 ts-node 和 nodemon 中看到的那样。如果您需要更多信息,请告诉我,因为这是我的第一篇文章。我真的很想知道答案是什么。
2020-05-30T00:03:12.201106+00:00 heroku[web.1]: Starting process with command `npm start`
2020-05-30T00:03:14.405285+00:00 app[web.1]:
2020-05-30T00:03:14.405303+00:00 app[web.1]: > discordtoornamentmanager@1.0.0 start /app
2020-05-30T00:03:14.405303+00:00 app[web.1]: > ts-node src/App.ts
2020-05-30T00:03:14.405304+00:00 app[web.1]:
2020-05-30T00:03:14.833655+00:00 app[web.1]: (node:23) ExperimentalWarning: The ESM module loader is experimental.
2020-05-30T00:03:14.839311+00:00 app[web.1]: TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /app/src/App.ts
2020-05-30T00:03:14.839312+00:00 app[web.1]: at Loader.defaultGetFormat [as _getFormat] (internal/modules/esm/get_format.js:65:15)
2020-05-30T00:03:14.839314+00:00 app[web.1]: at Loader.getFormat (internal/modules/esm/loader.js:113:42)
2020-05-30T00:03:14.839315+00:00 app[web.1]: at Loader.getModuleJob (internal/modules/esm/loader.js:244:31)
2020-05-30T00:03:14.839315+00:00 app[web.1]: at processTicksAndRejections (internal/process/task_queues.js:97:5)
2020-05-30T00:03:14.839316+00:00 app[web.1]: at Loader.import (internal/modules/esm/loader.js:178:17)
2020-05-30T00:03:14.847801+00:00 app[web.1]: …Run Code Online (Sandbox Code Playgroud) 注意:我知道以下问题是关于实验性功能的。我在 ts-node 讨论论坛上创建了一个克隆。不过,我相信 StackOverflow 拥有更广泛的曝光度,并且会在更短的时间内找到解决方案。
\n我正在尝试制作一个简单的脚本,从一个位置读取文件并处理它。这是我到目前为止所得到的,遵循#1007:
\n节点:v12.22.1
\nmy-app\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 .eslintrc.cjs\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 .gitignore\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 in\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 given.txt\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 node_modules\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 out\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 package-lock.json\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 package.json\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 src\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 helper.ts\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 main.ts\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 tsconfig.json\nRun Code Online (Sandbox Code Playgroud)\n包.json
\nmy-app\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 .eslintrc.cjs\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 .gitignore\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 in\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 given.txt\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 node_modules\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 out\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 package-lock.json\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 package.json\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 src\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 helper.ts\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 main.ts\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 tsconfig.json\nRun Code Online (Sandbox Code Playgroud)\ntsconfig.json
\n{\n "compilerOptions": {\n "target": "es5", /* Specify ECMAScript target version: \'ES3\' (default), \'ES5\', \'ES2015\', \'ES2016\', \'ES2017\', \'ES2018\', \'ES2019\', \'ES2020\', or \'ESNEXT\'. */\n "module": "ESNext", /* Specify module code …Run Code Online (Sandbox Code Playgroud) 您可能听说过 Deno,它是一个新的 TypeScript 运行时。
Deno 和普通 TypeScript 之间的一个主要区别是您必须在 import 语句中包含文件扩展名。例如:
import foo from './bar.ts'
^^
Run Code Online (Sandbox Code Playgroud)
我想编写与 Deno 和 Webpack 兼容的代码。
如何配置 Webpack 以允许使用.ts上述扩展名进行导入?
另外,如何防止以下 VSCode 错误?