我使用ts写了一个工具,并且将它发布至npm,但是我在其他项目中使用的时候提示“找不到模块“x6tool”或其相应的类型声明。ts(2307)”
下面是我这个工具的package文件及文件目录
这个包已经发布成功,并且在其他项目中安装成功,并且正常使用
相同的代码,vite 中可以 cra(基于 webpack)的不行。
import { useEffect } from 'react'
import X6Tool from 'x6tool'
import './App.css'
function App() {
useEffect(() => {
new X6Tool(document.querySelector('#map'))
}, [])
return (
<div>
<h1>Test</h1>
<div id="map"></div>
</div>
)
}
export default App
cra 编译报错:
Module not found: Error: Can't resolve './X6Tool/index' in 'E:\Projects\x6tool-test1\node_modules\x6tool\dist'
Did you mean 'index.js'?
BREAKING CHANGE: The request './X6Tool/index' failed to resolve only because it was resolved as fully specified
(probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.
ERROR in ./node_modules/x6tool/dist/index.js 1:0-36
Module not found: Error: Can't resolve './X6Tool/index' in 'E:\Projects\x6tool-test1\node_modules\x6tool\dist'
Did you mean 'index.js'?
BREAKING CHANGE: The request './X6Tool/index' failed to resolve only because it was resolved as fully specified
(probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.
webpack compiled with 1 error
大概意思是你的 package.json
里有 type: 'module'
,然后你 index.js
里引用是 /index
没有加 .js
或是 .mjs
后缀报的错。你没给你项目中报的错,我猜测可能和这个一样。
我看你 package.json
里只给了 ESM 格式的产物,而且用的 main
字段。我建议你给两种格式产物,main
字段对应 cjs
格式产物,module
字段对应 ESM 格式产物。
写对应的类型*.d.ts文件了嘛。你去你安装的node包里面看看。是不是少个类型文件。
帮你问了一下GPT
问题内容: 什么时候使用,更重要的是,为什么要使用它而不是? 问题答案: 从理论上讲,根据RFC 4329,。 假定的原因与该类型是可读还是可执行无关。这是因为语言/类型本身(而非通用参数)规定了自定义字符集确定机制。的子类型应该能够通过代理更改为另一个字符集,从而更改charset参数。JavaScript并非如此,因为: 一个。RFC表示用户代理应在脚本上进行BOM嗅探以确定类型(不过我不确定
我目前正在学习做rosalind问题(基本上是一堆与生物信息学相关的代码)。 我目前正在用以下类型表示一条DNA链: 我最初的原因是封装字节片,这样我就知道它只包含代表核苷酸的字节:。我意识到这显然没有保护,因为我可以简单地做: 也不再保证我的dna链包含一个字节数组,其中只有来自这四个字节的元素。 因为我的结构只包含一个字节数组是更好/更理想的做法: 还是让类型包含dna链更好?对于何时使用这两
我目前正在通过做rosalind问题(基本上是一堆生物信息学相关的代码katas)来学习Go。 我当前表示的DNA链类型为: 我最初的原因是封装字节片,这样我就知道它只包含代表核苷酸的字节:。我意识到这显然不是瓜分,因为我可以简单地做到: 由于我的结构只包含一个字节数组,这样做是否更好/更理想: 还是让类型包含dna链更好?对于何时使用这两种方法中的任何一种,有什么经验法则吗?
WebStorm 开发vue3+ts项目时类型定义完善但是template会识别不出类型 但是换种写法就好了 什么原因引起的?
问题内容: 与 我看到越来越多的JavaScript库在处理字符串时使用单引号。为何一个使用另一个原因?我认为它们几乎可以互换。 问题答案: 在不同的库中使用单一或双重的最可能原因是程序员的偏爱和/或API一致性。除了保持一致之外,请使用最适合该字符串的那个。 使用其他类型的引号作为文字: 这可能会变得复杂: ES6中的另一个新选项是使用以下字符的Template文字: 模板文字为以下内容提供了一
我正在学习Vue JS,发现有时我们导入{},有时我们导入时没有{}。请问有什么区别? 非常感谢。