【发布时间】:2021-04-28 13:40:23
【问题描述】:
我一直在构建一个打字稿应用程序,其中我从一个文件中导入了一些常量。 VS Code 的 Auto-Import 为我完成了这项工作,但是当我编译并运行文件时,它抛出了一个错误,因为它找不到模块。似乎错误来自导入语句没有文件扩展名,但它只出现在编译的 javascript 中,而不出现在 typescript 文件中。
index.ts:
import { __port__ } from "./constants";
import express from "express";
const app = express();
app.listen(__port__, () => console.log("listening on port" + __port__));
常量.ts:
export const __port__ = process.env.PORT || 3000;
node.js 错误信息:
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/af2111/Desktop/Coding/myapp/server/dist/constants' imported from /home/af2111/Desktop/Coding/myapp/server/dist/index.js
【问题讨论】:
标签: node.js typescript es6-modules