【问题标题】:Azure production typescript imports failAzure 生产打字稿导入失败
【发布时间】:2021-01-22 17:05:17
【问题描述】:

我正在尝试设置一个使用 typescript 开发的网络服务器,并且一切都在本地运行良好。没有关于使用或运行时的错误或警告。不过,我无法将它部署到 Azure;

// import inside website.ts
import { do_request } from "./api"
// breaks
do_request()


// function inside the module "api.ts"
export function do_request(name: string, data: any) {
    // there is infact stuff in here
}

在某个地方,会发生这种情况:

2021-01-22T16:39:13.961567336Z $ cross-env NODE_ENV=production nodemon --exec ts-node src/index.ts -e ts
2021-01-22T16:39:14.997665938Z [33m[nodemon] 2.0.7[39m
2021-01-22T16:39:15.003697468Z [33m[nodemon] to restart at any time, enter `rs`[39m
2021-01-22T16:39:15.006837988Z [33m[nodemon] watching path(s): *.*[39m
2021-01-22T16:39:15.006861089Z [33m[nodemon] watching extensions: ts[39m
2021-01-22T16:39:15.006872090Z [32m[nodemon] starting `ts-node src/index.ts`[39m
2021-01-22T16:39:34.553414244Z ... environment: production
2021-01-22T16:39:38.264762256Z ... caching
2021-01-22T16:39:57.536570340Z ... finished
2021-01-22T16:39:59.879985595Z ... server listening on port 8080
2021-01-22T16:40:01.061256273Z ... azure storage directory ready


2021-01-22T17:03:33.811212805Z 
2021-01-22T17:03:33.811396011Z /home/site/wwwroot/src/server/website.ts:150
2021-01-22T17:03:33.811428912Z      do_request(requestType, json)
2021-01-22T17:03:33.811441213Z   ^
2021-01-22T17:03:33.811449613Z TypeError: api_1.do_request is not a function
2021-01-22T17:03:33.811457813Z     at IncomingMessage.<anonymous> (/home/site/wwwroot/src/server/website.ts:150:3)
2021-01-22T17:03:33.817172614Z     at IncomingMessage.emit (node:events:388:22)
2021-01-22T17:03:33.817201815Z     at IncomingMessage.EventEmitter.emit (node:domain:470:12)
2021-01-22T17:03:33.817210915Z     at endReadableNT (node:internal/streams/readable:1295:12)
2021-01-22T17:03:33.817219316Z     at processTicksAndRejections (node:internal/process/task_queues:80:21)

我尝试过重新安装所有 npm 包,切换节点版本,切换导入;

// the same issue appears here, except it errors with "x has no constructor"
import Bot from "./bot"

// broken statement
const bot = new Bot()

【问题讨论】:

    标签: typescript azure


    【解决方案1】:

    您要部署到哪个 Azure 服务? Azure 函数?

    另外,你现在怎么样了?在 VS Code 或 CLI 中使用Azure Functions Core Tools。你试过https://github.com/mhoeger/typescript-azure-functions#deploy吗?

    【讨论】:

    • 我正在通过 vscode 进行部署。我还没有检查那个链接,因为我勇敢的谷歌搜索没有显示给我。我可能搞砸了构建过程,因为从 typescript 生成的 api.js 文件有一个旧的导出定义,而不是我使用的新名称会中断
    • 谢谢!链接有效。我必须添加一个脚本来编译打字稿。
    猜你喜欢
    • 2020-06-12
    • 1970-01-01
    • 2021-05-08
    • 2020-11-18
    • 1970-01-01
    • 2020-04-19
    • 2023-02-09
    • 2021-11-12
    • 2022-01-25
    相关资源
    最近更新 更多