node.js - 编译器无法从 node_modules/@types 中找到类型
问题描述
我尝试P5
从我的 node_modules 加载类型,但是当我编译我的代码时,终端返回此编译错误消息
Module not found: Error: Can't resolve 'p5' in '/Users/stan/En_cours/code/github/P5JS_TypeScript_WebPack/Template_V2/src'
@ ./src/sketch.ts 2:0-25 23:18-20
在我使用的代码中导入,import * as p5 from "p5";
但是当我阅读日志时,编译器尝试直接在src
文件夹中搜索,我找不到要求进入node_modules/@types/p5
.
有关信息,我是 TypeScript、NPM、Webpack 的初学者...
我也试过
import p5 from "../node_modules/@types/p5";
import * as p5 from "./node_modules/@types/p5";
我找到了这些链接,但没有找到可行的解决方案。
https://www.typescriptlang.org/docs/handbook/module-resolution.html
https://github.com/Microsoft/TypeScript/issues/16472
在我package.json
有
"devDependencies": {
"@types/p5": "^0.9.0
.../...
},
解决方案
我修复了一部分问题。这是打字稿版本的问题,不知为什么我的版本package.json
不是好版本,所以我用好的版本代替。另外还有一个导入p5
问题,比如@ChristopherChiche 并且知道问题的大小export.js
现在大约是 8MG 而之前是 10K,并且索引没有导出:(
我认为在导出过程P5
中添加了,不确定但闻到了。如果是这样,如何不导出p5
,因为我不需要,因为在 html 中它是这样写的<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/p5.js"></script>
链接项目: https ://github.com/StanLepunK/P5JS_typeScript_webPack/tree/master/Template_V2
export.js 8.49 MiB 0 [emitted] [big] export
Entrypoint export [big] = export.js
[1] (webpack)/buildin/global.js 472 bytes {0} [built]
[2] ./src/sketch.ts + 1 modules 1.27 KiB {0} [built]
| ./src/sketch.ts 826 bytes [built]
| ./src/Z_Position.ts 468 bytes [built]
+ 1 hidden module
WARNING in configuration
The 'mode' option has not been set, webpack will fallback to 'production' for this value. Set 'mode' option to 'development' or 'production' to enable defaults for each environment.
You can also set it to 'none' to disable any default behavior. Learn more: https://webpack.js.org/concepts/mode/
WARNING in asset size limit: The following asset(s) exceed the recommended size limit (244 KiB).
This can impact web performance.
Assets:
export.js (8.49 MiB)
WARNING in entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (244 KiB). This can impact web performance.
Entrypoints:
export (8.49 MiB)
export.js
WARNING in webpack performance recommendations:
You can limit the size of your bundles by using import() or require.ensure to lazy load some parts of your application.
For more info visit https://webpack.js.org/guides/code-splitting/
推荐阅读
- java - java.lang.NoClassDefFoundError:解析失败:Lorg/spongycastle/util/Strings Android Studio
- ios - 如何使用系统图标图像设置 UIButton 内部的色调?
- apache-spark - 在 Palantir Foundry 中为特定类型的所有列创建期望
- flutter - 如何在颤动中导航到另一个类的方法
- python - 如何检查所有元素是否属于一组?
- pytorch - TorchScript 模型导出中的重复分支
- javascript - 如何获取我在柏树字段下插入的文本长度
- python - 不允许使用饼干机械汤
- plot - 在 Maple 中线性化,绘制微分方程系统的分岔?
- mysql - sql根据父表求和