Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relative import path not prefixed #21440

Open
arthurwolf opened this issue Dec 3, 2023 · 10 comments · Fixed by #23602
Open

Relative import path not prefixed #21440

arthurwolf opened this issue Dec 3, 2023 · 10 comments · Fixed by #23602
Assignees
Labels
needs info needs further information to be properly triaged

Comments

@arthurwolf
Copy link

Version: latest

After a full day banging my head against walls trying to get ESM to work and failing, somebody recommended I try deno.

I just tried, and it does this:

run --check backend/index.ts
error: Relative import path "unrar" not prefixed with / or ./ or ../
    at file:///home/arthur/dev/ai/manga/ui/backend/index.ts:17:34

which is weird that it would fail like this, thinking unrar is a relative import when it seemingly had no problem with the 10 other modules before that:

import express from 'express';
import multer from 'multer';
import cors from 'cors';
import fs from 'fs';
import {fileTypeFromBuffer} from 'file-type';
import {readChunk} from 'read-chunk';
import path from 'path';
import {glob} from 'glob';
// Database.
import sequelize from '../../src/db/database';
import Book from '../../src/db/book';
import Page from '../../src/db/page';

// Zip and rar stuff.
import unzipper from 'unzipper';
import tar from 'tar';
import { Extract as Unrar } from 'unrar';

console.log("z");

what's going on here?

thanks

@bartlomieju
Copy link
Member

Can you share configuration files (Deno.json/package.json) and/or import mao files you have in your repository?

@arthurwolf
Copy link
Author

arthurwolf commented Dec 3, 2023 via email

@bartlomieju
Copy link
Member

not sure what a mao file is (and Google wasn't very helpful about that)

I meant "import map" :)

@bartlomieju bartlomieju added the bug Something isn't working label Dec 3, 2023
@arthurwolf
Copy link
Author

arthurwolf commented Dec 3, 2023 via email

@codingiswhyicry
Copy link

Experiencing this after an upgrade to deno 1.39.1, which no longer has support for import maps (I think). Error started occurring after changing from import maps -> content in root level deno.json file.

@dsherret
Copy link
Member

Sorry, I closed the wrong issue.

@dsherret dsherret reopened this May 13, 2024
@dsherret
Copy link
Member

@codingiswhyicry see issue #23057 for that one, which is unrelated to this (it's fixed now)

@dsherret dsherret added needs info needs further information to be properly triaged and removed bug Something isn't working labels May 13, 2024
@codingiswhyicry
Copy link

Thanks so much :-)

@dsherret
Copy link
Member

dsherret commented May 13, 2024

@arthurwolf I tried running that code sample and there's a lot of missing dependencies not defined in the package.json like cors, multer, express. When I try to run:

import { Extract as Unrar } from 'unrar';
console.log("z");

With a package.json like:

{
  "dependencies": {
    "unrar": "^0.2.0"
  }
}

I get:

error: Uncaught SyntaxError: The requested module 'unrar' does not provide an export named 'Extract'
import { Extract as Unrar } from 'unrar';
         ^

Looking at that package, it doesn't seem to provide an Extract export.

Would you be able to provide a fully reproducible example of the error you're encountering? (an example without redactions that anyone could run easily to reproduce the problem?)

@Jamesernator
Copy link

Jamesernator commented May 21, 2024

I am getting this also when importing in the REPL, the cause is importing a node-style module from outside of it's package, i.e. if we have:

base/
  example-package/
     node_modules/
     package.json
     example.js

If while in base/ we import from that package (where example.js imports glob) in the repl I get the error:

% deno
Deno 1.43.5
exit using ctrl+d, ctrl+c, or close()
REPL is running with all permissions allowed.
To specify permissions, run `deno repl` with allow flags.
> await import("./example-package/example.js")
Uncaught TypeError: Relative import path "glob" not prefixed with / or ./ or ../
    at file:///home/jamesernator/projects/example-package/example.js:1:22
    at async <anonymous>:1:22

The error doesn't happen with deno run --allow-all ./example-package/example.js, so I'm not sure exactly what is causing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs info needs further information to be properly triaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants