Reputation: 11
In parcel 1, I was able to import with tilde (~) which usually refers to the nearest directory or the root directory of the project. But, I recently upgraded to parcel 2 and it's complaining. How do I enable the ~ path resolvers in a typescript/react repo ? Do I need to write a resolver for that or is there any build-in support ? Is there any example for this setup ?
Upvotes: 1
Views: 1853
Reputation: 946
I'm afraid currently that can't be done (July 2022, parcel v2.6.2) even though the official docs say you can. I followed the docs, it didn't work. VS Code respects my tsconfig and resolves tilde imports as expected but the parcel command complains in the terminal.
It looks like a known issue (and another related issue)
There's a plugin (parcel-resolver-tspaths) that supposedly solves this issue but I haven't tried it yet.
See also a short blog post about this issue
Upvotes: 2
Reputation: 5250
works fine here. this is my package.json
{
"name": "my-pacakge",
"version": "1.0.9-alpha",
"description": "something",
"scripts": {
"start": "parcel index.html --open",
"build": "parcel build --public-url . index.html",
"pack": "npm-pack-zip"
},
"author": "",
"license": "ISC",
"dependencies": {},
"devDependencies": {
"bootstrap": "^5.0.2",
"npm-pack-zip": "^1.2.9",
"parcel": "^2.0.1"
},
"peerDependencies": {
"@parcel/transformer-sass": "^2.0.1"
}
}
Upvotes: 0
Reputation: 21377
try to add this to your tsconfig.json
...
"baseUrl": "./src",
"paths": {
"~/*": ["./*"]
},
...
Upvotes: 1