import - Deno:无法导入包含相对导入的库

标签 import rdf deno

我正在尝试编写一些使用 Deno 的代码和 rdflib 。并且惨遭失败。

这是我的测试程序:

// @deno-types="https://dev.jspm.io/npm:<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c3b1a7a5afaaa183f1edf1edf4" rel="noreferrer noopener nofollow">[email protected]</a>/lib/index.d.ts"
import { Namespace } from 'https://dev.jspm.io/npm:<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="710315171d181331435f435f46" rel="noreferrer noopener nofollow">[email protected]</a>/lib/index'

当我要求 deno 缓存远程包时,它失败了:

$ deno --unstable cache rdflib.ts
Check file:///home/ian/projects/personal/deno-experiments/rdflib.ts
error: TS2502 [ERROR]: 'thisArg' is referenced directly or indirectly in its own type annotation.
    bind<T>(this: T, thisArg: ThisParameterType<T>): OmitThisParameter<T>;
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    at asset:///lib.es5.d.ts:350:22

TS2614 [ERROR]: Module '"https://dev.jspm.io/npm:<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="235147454f4a4163110d110d14" rel="noreferrer noopener nofollow">[email protected]</a>/lib/query"' has no exported member 'Query'. Did you mean to use 'import Query from "https://dev.jspm.io/npm:<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="acdec8cac0c5ceec9e829e829b" rel="noreferrer noopener nofollow">[email protected]</a>/lib/query"' instead?
import { Query } from './query';
         ~~~~~
    at https://dev.jspm.io/npm:<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="cbb9afada7a2a98bf9e5f9e5fc" rel="noreferrer noopener nofollow">[email protected]</a>/lib/index.d.ts:16:10

TS2614 [ERROR]: Module '"https://dev.jspm.io/npm:<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="aedccac8c2c7ccee9c809c8099" rel="noreferrer noopener nofollow">[email protected]</a>/lib/updates-via"' has no exported member 'UpdatesSocket'. Did you mean to use 'import UpdatesSocket from "https://dev.jspm.io/npm:<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="96e4f2f0fafff4d6a4b8a4b8a1" rel="noreferrer noopener nofollow">[email protected]</a>/lib/updates-via"' instead?
import { UpdatesSocket } from './updates-via';
         ~~~~~~~~~~~~~
    at https://dev.jspm.io/npm:<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c5b7a1a3a9aca785f7ebf7ebf2" rel="noreferrer noopener nofollow">[email protected]</a>/lib/index.d.ts:26:10

TS2614 [ERROR]: Module '"https://dev.jspm.io/npm:<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="780a1c1e14111a384a564a564f" rel="noreferrer noopener nofollow">[email protected]</a>/lib/updates-via"' has no exported member 'UpdatesVia'. Did you mean to use 'import UpdatesVia from "https://dev.jspm.io/npm:<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b3c1d7d5dfdad1f3819d819d84" rel="noreferrer noopener nofollow">[email protected]</a>/lib/updates-via"' instead?
import { UpdatesVia } from './updates-via';
         ~~~~~~~~~~
    at https://dev.jspm.io/npm:<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="126076747e7b7052203c203c25" rel="noreferrer noopener nofollow">[email protected]</a>/lib/index.d.ts:27:10

TS2749 [ERROR]: 'Store' refers to a value, but is being used as a type here. Did you mean 'typeof Store'?
    at https://dev.jspm.io/npm:<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7c0e181a10151e3c4e524e524b" rel="noreferrer noopener nofollow">[email protected]</a>/lib/index.d.ts:32:32

... many more lines ...

TS2614 [ERROR]: Module '"https://dev.jspm.io/npm:<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f98b9d9f95909bb9cbd7cbd7ce" rel="noreferrer noopener nofollow">[email protected]</a>/lib/utils/termValue"' has no exported member 'termValue'. Did you mean to use 'import termValue from "https://dev.jspm.io/npm:<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a2d0c6c4cecbc0e2908c908c95" rel="noreferrer noopener nofollow">[email protected]</a>/lib/utils/termValue"' instead?
export { termValue } from './utils/termValue';
         ~~~~~~~~~
    at https://dev.jspm.io/npm:<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="86f4e2e0eaefe4c6b4a8b4a8b1" rel="noreferrer noopener nofollow">[email protected]</a>/lib/index.d.ts:40:10

Found 44 errors.

据我所知,问题出在远程代码中执行相对导入的行。这种相对导入不适用于 Deno,还是我错过了一些重要的步骤,或者我的方法注定失败?

版本信息:

$ deno --version
deno 1.12.2 (release, x86_64-unknown-linux-gnu)
v8 9.2.230.14
typescript 4.3.5

最佳答案

问题不在于它们是相对说明符,而在于它们不完全限定。来自手册第 6.6 节:

Can I use TypeScript not written for Deno?

Maybe. That is the best answer, we are afraid. For lots of reasons, Deno has chosen to have fully qualified module specifiers. In part this is because it treats TypeScript as a first class language. Also, Deno uses explicit module resolution, with no magic. This is effectively the same way browsers themselves work, though they don't obviously support TypeScript directly. If the TypeScript modules use imports that don't have these design decisions in mind, they may not work under Deno.

Also, in recent versions of Deno (starting with 1.5), we have started to use a Rust library to do transformations of TypeScript to JavaScript in certain scenarios. Because of this, there are certain situations in TypeScript where type information is required, and therefore those are not supported under Deno. If you are using tsc as stand-alone, the setting to use is "isolatedModules" and setting it to true to help ensure that your code can be properly handled by Deno.

One of the ways to deal with the extension and the lack of Node.js non-standard resolution logic is to use import maps which would allow you to specify "packages" of bare specifiers which then Deno could resolve and load.

关于import - Deno:无法导入包含相对导入的库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68552759/

相关文章:

hadoop - Sqoop导入-源表架构更改

java - Jena 未从导入的 RDF 文件加载数据

Sparql - 将限制条件应用于谓词

unit-testing - 在 Deno 中对 global.fetch 进行 stub /监视

javascript - 如何像 console.log 一样对任何类型的值进行字符串化?

javascript - 在使用 TypeScript 编写时,如何查看 Deno 转译的 javascript?

python - 无法导入 Python 类

git - 将更改从外部未跟踪目录复制到单独的 Git 工作副本

javascript - 更新 Electron 和changin Node 后的错误积分为true

xml - 使用 XSLT 将 XML 文件转换为 RDF/XML