question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeScript ```import '@types/handlebars';``` leads to "Cannot resolve dependency '@types/handlebars'"

See original GitHub issue

Choose one: 🐛 bug report

// index.ts
import '@types/handlebars';

parsel index.ts

X Cannot resolve dependency ‘@types/handlebars

🎛 Configuration (.babelrc, package.json, cli command)

Babel: no

🤔 Expected Behavior

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';

😯 Current Behavior

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’; | ^

💁 Possible Solution

No idea.

🔦 Context

It’s hard/impossible to continue working with parcel-bundler and Handlebars library with TypeScript which requires the declaration file to be imported.

💻 Code Sample

See above.

🌍 Your Environment

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.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
fathybcommented, Jan 23, 2018

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"]
     }
  }
}
0reactions
github-actions[bot]commented, Jan 18, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

typescript error when compiling node module - Stack Overflow
I have deleted all node modules and added one by one that is mentioned in error when run npm start . Here's updated...
Read more >
Documentation - Module Resolution - TypeScript
A relative import is resolved relative to the importing file and cannot resolve ... Use non-relative paths when importing any of your external...
Read more >
Common TypeScript module problems and how to solve them
A firm understanding of TypeScript modules system. Problem 1: Irregular location of dependencies. On a normal occasion, the node-modules ...
Read more >
Features | Vite
Rewrite the imports to valid URLs like /node_modules/.vite/deps/my-dep.js?v=f3sf2ebd so that the browser can import them properly. Dependencies are Strongly ...
Read more >
eslint-import-resolver-typescript - npm
Prefer resolving @types/* definitions over plain .js / .jsx; Multiple tsconfigs support just like normal; imports/exports fields support in ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found