rally25rs
rally25rs•10mo ago

'Relative import path not prefixed' error from @types/express .d.ts file?

Converting an express mjs project to deno & TS, and running into an issue using code from this example: https://docs.deno.com/runtime/tutorials/how_to_with_npm/express Using
// @deno-types="npm:@types/express@4.17.15"
import express from "npm:express@4.18.2";
// @deno-types="npm:@types/express@4.17.15"
import express from "npm:express@4.18.2";
results in
Task start deno run --allow-read --allow-env --allow-net index.ts
error: Relative import path "qs" not prefixed with / or ./ or ../ and not in import map from "file:///Users/jeff/Library/Caches/deno/npm/registry.npmjs.org/@types/express/4.17.18/index.d.ts"
at file:///Users/jeff/Library/Caches/deno/npm/registry.npmjs.org/@types/express/4.17.18/index.d.ts:21:21
Task start deno run --allow-read --allow-env --allow-net index.ts
error: Relative import path "qs" not prefixed with / or ./ or ../ and not in import map from "file:///Users/jeff/Library/Caches/deno/npm/registry.npmjs.org/@types/express/4.17.18/index.d.ts"
at file:///Users/jeff/Library/Caches/deno/npm/registry.npmjs.org/@types/express/4.17.18/index.d.ts:21:21
Whats extra strange is that the error mentions @types/express/4.17.18 which isn't even the version in my code:
// @deno-types="npm:@types/express@4.17.15"
// @deno-types="npm:@types/express@4.17.15"
deno --version is:
deno 1.37.1 (release, x86_64-apple-darwin)
v8 11.8.172.6
typescript 5.2.2
deno 1.37.1 (release, x86_64-apple-darwin)
v8 11.8.172.6
typescript 5.2.2
Any suggestions on how to further debug this issue?
How to use Express with Deno | Deno Docs
Express is a popular web framework known for being
2 Replies
rally25rs
rally25rs•10mo ago
ok figured out the problem... somehow one of my source files got this line in it:
import e from "../../../Library/Caches/deno/npm/registry.npmjs.org/@types/express/4.17.18/index.d.ts";
import e from "../../../Library/Caches/deno/npm/registry.npmjs.org/@types/express/4.17.18/index.d.ts";
For some reason VSCode wants to auto-import something direct from the deno cache? 😕
No description
Deno AI Helper
Deno AI Helper•10mo ago
Based on the documentation, Deno supports importing npm packages using npm: specifiers. However, it seems like you're encountering an issue with relative import paths in the @types/express package. The error message you're seeing suggests that the import statement in the @types/express package is trying to import the qs module using a relative path that doesn't start with /, ./, or ../. This is not supported in Deno, which expects all module specifiers to be fully qualified URLs or paths. One possible reason for the discrepancy in the version number could be that Deno is fetching a cached version of the @types/express package. Deno caches remote imports in a special directory on your machine, and it's possible that an older version of the package is being used. As for debugging this issue, here are a few suggestions: 1. Clear Deno's cache using the deno cache --reload command. This will force Deno to fetch the latest version of all remote imports the next time you run your program. 2. Check the @types/express package on npm to see if it uses relative import paths that don't start with /, ./, or ../. If it does, this could be the source of the problem. 3. Consider using an import map to map the qs module to a URL or path that Deno can resolve. Import maps are a way of telling Deno where to find certain modules. You can learn more about them in the Deno manual. Remember that Deno's support for npm packages is still experimental and there might be cases where certain packages or types don't work as expected. If you continue to encounter issues, consider opening an issue on the Deno GitHub repository to get help from the Deno community.