Reputation: 83
I have created a Asp.net core React project using the build in template in visual studio 2019
The project created a separated folder called ClientApp where the React project live. I have done npm init.
I have added a jsconfig.json file at the root of the folder ClientApp as follow.
Folders
jsconfig.json
When I try to import a component using the absolute paths defined in jsconfig, the compiler does not find the path.
and generate the error
I tried to remove the "./" starting the path from "./src/components/" to "src/components/" like below
But the error is still there
UPDATE
based on this thread https://dev.to/larswaechter/path-aliases-with-typescript-in-nodejs-4353 , when configuring alias in jsconfig.json file, then you can use the new path aliases for module imports in your application. There occur any errors in your IDE or when you compile the code.
However, When you try compile the TS code into JS you won't see any errors. But as soon as you run your compiled JS code you will get an error:
For example: Error: Cannot find module '@modules/user' That's because JS can't resolve the modules for the declared path aliases... Based on the article it can be solved by installing a npm package called module-alias.
Upvotes: 1
Views: 3329
Reputation: 760
Which you have been set baseUrl
with .
you don't need add ./
in paths
property
"baseUrl": ".",
"paths": {
"@Components/*": [ "src/components/*" ]
}
Upvotes: 0