-
Notifications
You must be signed in to change notification settings - Fork 20
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
Bad alias resolution when the main process references the common folder #1
Comments
I'm also having this same issue. So far in my research it appears that you may be able to fix this by using an |
i am also facing the same issue... does anyone has some solution |
@jdamon96 @DevelopAppWithMe import type {
CompilerOptions,
Diagnostic,
FormatDiagnosticsHost,
} from "typescript";
import * as ts from "ttypescript";
import * as path from "path";
import * as os from "os";
import { CompileError, WatchMain, outDirMain, mainPath } from "./common";
let diagnosticErrors: Array<CompileError> = [];
const formatHost: FormatDiagnosticsHost = {
getCanonicalFileName: (filepath) => filepath,
getCurrentDirectory: ts.sys.getCurrentDirectory,
getNewLine: () => ts.sys.newLine,
};
function reportDiagnostic(diagnostic: Diagnostic) {
if (!diagnostic.file || !diagnostic.start || !diagnostic.length) {
return;
}
const diagnosticMessage = ts.flattenDiagnosticMessageText(
diagnostic.messageText,
formatHost.getNewLine()
);
const filepath = diagnostic.file.fileName.replace(process.cwd(), "");
const { start } = diagnostic;
const len = diagnostic.length;
const linesOfCode = diagnostic.file.text.split(os.EOL);
const line = diagnostic.file.text.substr(0, start + 1).split(os.EOL).length;
const lineStart =
diagnostic.file.text.substring(0, start + 1).lastIndexOf(os.EOL) + 1;
const col = start - lineStart;
const compileError: CompileError = {
location: {
column: col,
file: filepath,
length: len,
line,
lineText: linesOfCode[line - 1],
},
message: diagnosticMessage,
};
diagnosticErrors.push(compileError);
}
export const watchMain: WatchMain = (
reportError,
buildStart,
buildComplete,
notFoundTSConfig
) => {
const configPath = path.join(mainPath, "tsconfig.json");
if (!configPath) {
notFoundTSConfig();
}
const createProgram = ts.createSemanticDiagnosticsBuilderProgram;
const host = ts.createWatchCompilerHost(
configPath,
{
sourceMap: true,
},
ts.sys,
createProgram,
reportDiagnostic,
(
diagnostic: Diagnostic,
_: unknown,
options: CompilerOptions,
errorCount?: number
) => {
if (!!errorCount && errorCount > 0) {
reportError(diagnosticErrors);
diagnosticErrors = [];
} else if (diagnostic.code === 6194) {
buildComplete(outDirMain);
} else if (diagnostic.code === 6032 || diagnostic.code === 6031) {
buildStart();
}
}
);
ts.createWatchProgram(host);
};
=== tsconfig ===
{
"paths": {
"@main/*": [
"main/*"
],
"@renderer/*": [
"renderer/*"
],
"@common/*": [
"common/*"
],
},
}``` |
Did anyone fix this using esbuild ? |
Likewise, I get the same error for aliases and for relative paths, i.e. |
@anup-a I have fix this using "esbuild-node-externals" and set bundle true import { nodeExternalsPlugin } from "esbuild-node-externals";
esbuild.build({
...
plugins: [nodeExternalsPlugin()],
bundle: true
...
}); |
I'm sorry I'm not a native English speaker. This is my problem
When I tried to reference the common configuration, I couldn't find the correct path in the packed dist directory,
It seems that my configuration is not bundled correctly
index.js in dist directory
error stack
tree
how can i fix it ?
The text was updated successfully, but these errors were encountered: