Skip to content

Self imports are not working #86

Closed
@piranna

Description

@piranna

When doing a self-import (at least for scoped packages) I get a n/no-missing-import error. I'm doing it for my project tests files, and when debugging it, I've traced it down to

// node_modules/import-meta-resolve/lib/package-json-reader.js
var import_fs = __toESM(require("fs"), 1);
var import_path = __toESM(require("path"), 1);
var reader = { read };
var package_json_reader_default = reader;
function read(jsonPath) {
return find(import_path.default.dirname(jsonPath));
}
function find(dir) {
try {
const string = import_fs.default.readFileSync(import_path.default.toNamespacedPath(import_path.default.join(dir, "package.json")), "utf8");
return { string };
} catch (error) {
if (error.code === "ENOENT") {
const parent = import_path.default.dirname(dir);
if (dir !== parent)
return find(parent);
return { string: void 0 };
}
throw error;
}
}
, where for an input file it's looking it's package.json file and returning its contend when called from
const source = package_json_reader_default.read(path4).string;
. Problem is that at
const packageConfig2 = getPackageConfig(packageJsonPath, specifier, base);
if (packageConfig2.exports !== void 0 && packageConfig2.exports !== null)
return packageExportsResolve(packageJsonUrl, packageSubpath, packageConfig2, base, conditions).resolved;
if (packageSubpath === ".")
return legacyMainResolve(packageJsonUrl, packageConfig2, base);
return new import_url2.URL(packageSubpath, packageJsonUrl);
is being used with the original requested path instead of the package root one, so file resolution fails.

On the other hand, I've found that in fact this file is a transpiled one, probably generated with webpack or something like that, so it's ugly to work with it. Original import-meta-resolve exists, and it's updated from two months ago, so why don't use it instead using a big blob?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions