Challenge
My attempt to configure path alias in my TypeScript project was met with failure. Two errors arose during the execution of npm start
:
(despite Visual Studio Code being able to locate imported files without any warnings)Module not found: Error: Can't resolve '~/App' in 'D:\work\workbench\templates\template-fe-pure\src'
Resolve error: Cannot find module 'node:fs'
Here is how I attempted to import using path alias:
import App from "./App";
-> import App from "~/App";
In my
tsconfig.json
: "baseUrl": ".","paths": {"~/*": ["./src/*"]},
(full file provided below)
System Details
- Create React App with TypeScript template
<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f49187989d9a80d9849881939d9ad99d99849b8680b4c6dac6c2dac4">[email protected]</a>
: inclusion made for path alias purposes as described above<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7114021d181f055c181c011e03055c0314021e1d0714035c0508011402120318010531425f435f44">[email protected]</a>
Configuration Files
.eslintrc.json
{
// Configuration details go here ...
}
tsconfig.json
{
// Compiler options and configurations listed here ...
}
Error Breakdown
ERROR
[eslint]
src\index.tsx
Line 1:1: Resolve error: Cannot find module 'node:fs'
Require stack:
- D:\work\workbench\templates\template-fe-pure\node_modules\eslint-import-resolver-typescript\lib\index.cjs
- D:\work\workbench\templates\template-fe-pure\node_modules\eslint-module-utils\resolve.js
- D:\work\workbench\templates\template-fe-pure\node_modules\eslint-plugin-import\lib\rules\no-unresolved.js
- D:\work\workbench\templates\template-fe-pure\node_modules\eslint-plugin-import\lib\index.js
- D:\work\workbench\templates\template-fe-pure\node_modules\@eslint\eslintrc\dist\eslintrc.cjs
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
// Additional stack trace information ...
Search for more insights on each encountered error.