【Azure Developer】在使用Azure Bot Service JavaScript的实例代码遇见Cannot find module 'node:crypto'

问题描述

从Github中下载了JavaScript的Bot Service EchoBot实例代码,本地执行,总是报错 Cannot find module 'node:crypto'

 错误信息

Error: Cannot find module 'node:crypto'
Require stack:
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
at Function.Module._load (internal/modules/cjs/loader.js:746:27)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:92:18)
at Object.<anonymous> (C:\js_echo_bot\node_modules\botframework-schema\node_modules\uuid\dist\rng.js:7:42)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:14)
at Module.require (internal/modules/cjs/loader.js:974:19) {
code: 'MODULE_NOT_FOUND',

 

 

问题解答

咨询了M365 Copilot后,找到了答案。就是因为本地的NodeJs版本太低的原因。

 

 

1. 检查 Node.js 版本:确保使用的 Node.js 版本支持 node:crypto 模块。

如果使用的是较旧版本的 Node.js,可能会因为不识别 node:* 语法而出现此错误。更新到 Node.js 版本 16 或更高版本应该可以解决此问题。

 

对于 Node.js 版本 16 及更高版本,应该使用:

const crypto = require('node:crypto'); 

旧版本,则需要使用:

const crypto = require('crypto');

 

 

参考资料

Error

Error: Cannot find module 'node:process'

Problem

This is caused by Node 14, which doesn't understand new syntax "node:*".

Node 14 used to have syntax:

require moduleName

However, in version 16 this was changed to:

require node:moduleName

Solution

Update to Node Version 16.

 

posted @   路边两盏灯  阅读(16)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
历史上的今天:
2022-11-11 【Azure API 管理】Azure APIM服务集成在内部虚拟网络后,在内部环境中打开APIM门户使用APIs中的TEST功能失败
2021-11-11 【Azure 应用程序见解】通过无代码方式在App Service中启用Application Insights后,如何修改在Application Insights中显示的App Service实例名呢?
点击右上角即可分享
微信分享提示