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.

Cannot resolve typescript imports

See original GitHub issue

Current Behavior

When attempting to use ts-loader to resolve typescript files, haul says it is unable to resolve the module. When trying to import a ts component with the line import { SomeComponent } from './some-component';

You get the following error from haul ERROR in ./src/index.android.tsx Module not found: Error: Can't resolve './some-component' in 'C:\Users\gusta\Documents\rn-typescript-example\src'@ ./src/index.android.tsx 15:23-50 @ multi ./~/haul-cli/src/utils/polyfillEnvironment.js ./src/index.android.tsx (TSC gives no errors when compiling this)

if you try with the file extension, as: import { SomeComponent } from './some-component.tsx'; Haul works fine, but react native crashes runtime with undefined is not an object

I have created a reproduction repo: https://github.com/GeeWee/rn-typescript-example

Expected Behavior

I expect it to resolve and transform the typescript file properly.

Haul Configuration (webpack.haul.js)

module.exports = ({ platform }, { module }) => ({
  entry: `./src/index.${platform}.tsx`,
  module: {
    ...module,
    rules: [
        {
          test: /\.tsx?$/,
          loader: 'ts-loader'
        },
        ...module.rules
      ]
  }
});

Your Environment

software version
Haul 0.5.0
react-native 0.42.3
node 7.7.4
npm or yarn yarn 0.21.3
typescript 2.2.2
ts-loader 2.0.3

Issue Analytics

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

github_iconTop GitHub Comments

7reactions
cbrevikcommented, May 9, 2017

I had the exact same problem yesterday, and you need to set extensions under resolve. I’ve got a working example here: https://github.com/cbrevik/rn-typescript-example/blob/master/webpack.haul.js

E.g.

  resolve: {
    ...resolve,
    extensions: ['.ts', '.tsx', `.${platform}.ts`, '.native.ts', `.${platform}.tsx`, '.native.tsx', ...resolve.extensions],
  },

Edit: Opened a PR to flesh out example project a bit more (https://github.com/nixterrimus/rn-typescript-example/pull/3)

0reactions
EhsanJahooncommented, Jun 9, 2019
Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack cant resolve TypeScript modules - Stack Overflow
Webpack does not look for .ts files by default. You can configure resolve.extensions to look for .ts . Don't forget to add the...
Read more >
Common TypeScript module problems and how to solve them
Solution 2: Locate the module and resolve imports ; "*" value in the array means the exact name of the module, while the...
Read more >
Documentation - Module Resolution - TypeScript
A relative import is resolved relative to the importing file and cannot resolve to an ambient module declaration. You should use relative imports...
Read more >
Configuring Module Resolution On Typescript and Jest
Step 4: Configuring the Jest runtime to resolve modules. ... Cannot find module '@/repositories/person' from 'index.spec.ts'> 1 | import * as ...
Read more >
Fixing The "Cannot Find Module" Error In TypeScript
Solution #1 - Install the package · Solution #2 - Re-install your dependencies · Solution #3 - Verify the import's name · Solution...
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