Choose one: ๐ bug report
// index.ts
import '@types/handlebars';
parsel index.ts
X Cannot resolve dependency '@types/handlebars'
Babel: no
The import command tells TypeScript to include a declaration file. Without this line any reference to Handlebars module are highlighted as invalid (PhpStorm). Even if the JS file for handlebars is imported with
import 'handlebars/dist/handlebars.min.js';
parcel entry.html
Server running at http://localhost:1234
ร RenderOpportunities.ts:3:8: Cannot resolve dependency '@types/handlebars'
1 | 'use strict';
2 |
3 | import '@types/handlebars';
| ^
No idea.
It's hard/impossible to continue working with parcel-bundler and Handlebars library with TypeScript which requires the declaration file to be imported.
See above.
parcel -V
1.4.1
node -v
v9.3.0
npm -v
5.6.0
yarn -v
1.3.2
ver
Microsoft Windows [Version 6.1.7601]
Thanks.
It may be related to https://github.com/Microsoft/TypeScript/issues/9725 but
> tsc index.ts
does not complain about anything.
It's due to the fact that Parcel doesn't use the TypeScript compiler but the the transpiler, it doesn't do import ellidation or any type-checking related transformations.
Solution:
import '@types/handlebars' from index.tscompileOptions:js
{
"compilerOptions": {
// ...
"types": ["handlebars"]
}
}
Thank you. This helped a lot. I have a different (but related to handlebars) issue.
$ parcel entry.html
Server running at http://localhost:1234
ร ...\node_modules\handlebars\lib\index.js: Could not statically evaluate fs call
AFAIK, the issue is that handlebars module contains node fs call which is not available in the browser target.
Webpack has a workaround for this. They define an alias for 'handlebars' module which point to a different file.
Any suggestion for Parcel?
My import code
import * as Handlebars from 'handlebars';
Thanks.
I created #587 to warn instead of throwing when a fs call cannot be statically evaluated, you can try it while it's being reviewed.
If it does not work I'm not aware of a resolve alias feature in Parcel, the TypeScript plugin supports TypeScript path rewriting using the paths compiler option, you can use it if the handlebars typings declares the handlebars/dist/handlebars.min.js module.
{
"compilerOptions": {
// ...
"baseUrl": ".",
"paths": {
"handlebars": ["handlebars/dist/handlebars.min.js"]
}
}
}
I got a similar error when I use custom paths:
__tsconfig__
"baseUrl": "./",
"paths": {
"@src/*": [
"src/*"
]
},
__output__
yarn build (2s 663ms) โ
yarn run v1.5.1
$ env NODE_ENV=production parcel build --no-source-maps --experimental-scope-hoisting --detailed-report --public-url ./
๐จ /home/joseluisq/myapp/src/main.tsx:2:37: Cannot resolve dependency '@src/app'
at Resolver.resolve (/home/joseluisq/myapp/node_modules/parcel-bundler/src/Resolver.js:70:17)
at <anonymous>
error An unexpected error occurred: "Command failed.
But in development mode curiously works.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs.
Most helpful comment
I created #587 to warn instead of throwing when a fs call cannot be statically evaluated, you can try it while it's being reviewed.
If it does not work I'm not aware of a resolve alias feature in Parcel, the TypeScript plugin supports TypeScript path rewriting using the
pathscompiler option, you can use it if thehandlebarstypings declares thehandlebars/dist/handlebars.min.jsmodule.