wu_trulli 2023-03-12 13:32 采纳率: 62.5%
浏览 69
已结题

Error: Cannot find package 'assert' imported from

test文件夹下有一个developer.test.ts文件,第一句就是import * as assert from 'assert/strict',没有显示语法错误,我也检查了node_modules/@types/node/asset/strict.d.ts这个文件是存在的,代码如下:

declare module 'assert/strict' {
    import { strict } from 'node:assert';
    export = strict;
}
declare module 'node:assert/strict' {
    import { strict } from 'node:assert';
    export = strict;
}

当我用如下命令:npm run test:developer 测试文件时,报错:Error: Cannot find package 'assert' imported from C:\Users\xiaola\btp1\ase\test\developer.test.ts

tsconfig.json文件如下:

{
  "compilerOptions": {
      "module": "Node16",
      "outDir": "dist",
      "rootDir": ".",
      "target": "ES2020",
      "strict": true,
      "skipLibCheck": true,
      "sourceMap": true,
      "lib": ["ES2020"]
  },
  "include": [
      "src/**/*.ts",
      "test/**/*.ts"
  ],
  // Most ts-node options can be specified here using their programmatic names.
  "ts-node": {
      "esm": true,
      "compilerOptions": {
          // compilerOptions specified here will override those declared below,
          // but *only* in ts-node.  Useful if you want ts-node and tsc to use
          // different options with a single tsconfig.json.
      },
  }
}


  • 写回答

5条回答 默认 最新

  • 游一游走一走 2023-03-12 15:05
    关注

    node的版本对吗?用16+的看看,你的配置没啥问题

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

问题事件

  • 系统已结题 3月20日
  • 已采纳回答 3月12日
  • 创建了问题 3月12日

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么