When import a library with has the same name as the local file it replace for a local alias
See original GitHub issueIt has happened in one of my projects that having a library with the same name as one of the project folders/file during the compilation process the reference to the npm package is replaced by the address of the local folder.
This happens only when upgrading to versions higher than 1.4.0.
Example:
folder structure: src/ esbuild.js exampleFail.js
exampleFail.ts
import esbuildLocal from '~/esbuild';
import esbuild from 'esbuild';
export function isEmpty(value: unknown): boolean {
if (!value || value === '0' || (typeof value === 'string' && value.match(/^[0][.][0]{2,}/))) {
return true;
}
console.log(esbuild)
console.log(esbuildLocal)
return false;
}
exampleFail.js
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
var __export = (target, all) => {
__markAsModule(target);
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __reExport = (target, module2, desc) => {
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
for (let key of __getOwnPropNames(module2))
if (!__hasOwnProp.call(target, key) && key !== "default")
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
}
return target;
};
var __toModule = (module2) => {
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
};
__export(exports, {
isEmpty: () => isEmpty
});
var import_esbuild = __toModule(require("./esbuild"));
var import_esbuild2 = __toModule(require("./esbuild"));
function isEmpty(value) {
if (!value || value === "0" || typeof value === "string" && value.match(/^[0][.][0]{2,}/)) {
return true;
}
console.log(import_esbuild2.default);
console.log(import_esbuild.default);
return false;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
isEmpty
});
var import_esbuild2 = __toModule(require(“./esbuild”)); // ERROR - This should not have been modified by tsc-alias
tsconfig.json
{
"compilerOptions": {
"lib": ["es2019", "DOM"],
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"removeComments": true,
"moduleResolution": "node",
"declaration": true,
"module": "CommonJS",
"noUnusedLocals": true,
"noUnusedParameters": true,
"sourceMap": true,
"target": "es2019",
"outDir": "../out",
"baseUrl": "./",
"types": ["jest", "node"],
"typeRoots": ["./types", "./node_modules/@types"],
"paths": {
"~/*": ["Test 4/src/*"]
}
},
"include": ["Test 4/src/utils.js","Test 4/src/esbuild.js","Test 4/src/exampleFail.ts"],
"exclude": ["node_modules/**/*", ".vscode/**/*", "tests/**/*"]
}
Issue Analytics
- State:
- Created a year ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Change Name of Import in Java, or import two classes with the ...
There is no import aliasing mechanism in Java. You cannot import two classes with the same name and use both of them unqualified....
Read more >How to import and alias package names? - Golang Programs
Go inside the vehicle directory and run the following command to create a go module named vehicle. go mod init vehicle. The above...
Read more >Module Resolution or Import Alias: The Final Guide - Raul Melo
Solution. Module resolution or import alias is a way we can emulate the same way we import node_modules but with our internal code....
Read more >DO NOT USE! Use import mapping instead · Issue #113 - GitHub
An interest afterthought to replacing this module is that import mapping does ... import aliases for local packages when the file dependency specifier...
Read more >Absolute vs Relative Imports in Python
When Python finds the module, it binds it to a name in the local scope. This means that abc is now defined and...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@tjtrujillo It seems like typescript compiles the files in the
Test 4/src/
directory to the top-level out directory, leading to a path mismatch. Could you try changing"~/*": ["Test 4/src/*"]
to"~/*": ["Test 4/src/*", "*"]
?@raouldeheer finally with that last change it has worked. Thank you very much I close the issue