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 ?
Asked
Active
Viewed 1,531 times
0
-
helpfull? https://github.com/parcel-bundler/parcel/issues/2813 – marsh-wiggle Oct 15 '20 at 22:03
3 Answers
2
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)
Solution?
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

Taitu-lism
- 856
- 9
- 10
1
try to add this to your tsconfig.json
...
"baseUrl": "./src",
"paths": {
"~/*": ["./*"]
},
...

Fateh Mohamed
- 20,445
- 5
- 43
- 52
0
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"
}
}

Johansrk
- 5,160
- 3
- 38
- 37