brunch / typescript-brunch

Adds TypeScript support to Brunch

Home Page:http://brunch.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

error: Compiling of app/vendor.ts failed. Cannot read property 'resolvedModule' of undefined

davidjsalazarmoreno opened this issue · comments

Hi everyone, I'm trying to import libs in npm_modules via import keyword but had the next error: "error: Compiling of app/vendor.ts failed. Cannot read property 'resolvedModule' of undefined".

In my fork of the plugin I added some fixes than solve 'resolvedModule' issue.
https://github.com/davidjsalazarmoreno/brunch-typescript/blob/master/index.js#L14
https://github.com/davidjsalazarmoreno/brunch-typescript/blob/master/index.js#L58

But seems not work with latest versions of brunch plugin, the error aparently gone but not produce any javascript file from .ts with node_modules imports.

You can see the issue in this repository: https://github.com/davidjsalazarmoreno/brunch-typescript-issue

tsconfig: https://github.com/davidjsalazarmoreno/brunch-typescript-issue/blob/master/tsconfig.json
brunch-config: https://github.com/davidjsalazarmoreno/brunch-typescript-issue/blob/master/brunch-config.js

Thanks everyone.

I too am running into problems with the latest version. It cannot find any of my relative imports. I just isolated it to the brunch-typescript plugin now. I will try and see if I can come up with an isolated test after dinner. 🍔

I've found it first happens when installing this commit: 690ba39
And can fix it by reverting this line.
To reproduce try the following:

// app/math.ts
export default function sum(a, b) {
  return a + b;
}
// app/main.ts
import sum from './math'

function main() {
  return sum(1, 2);
}
brunch b
02 Apr 01:22:19 - error: Compiling of app/main.ts failed. Error 2307: Cannot find module './math'. (Line: 1, Col: 17) 

@speg @davidjsalazarmoreno please revert to 1.8.1 for the time being.

I agree revert to 1.8.1 for now. Even if this was working properly I suspect this change will be breaking for some people where certain errors were being ignored. Unfortunately this project doesn't really follow SemVer.

The TypeScript compiler spits out a bunch of errors when operating in single module mode which can be ignored, I've clearly not filtered out all of them. Let me look into this one.

I've isolated it down to this line. I created a PR #14 that removes it.

OK, so, @davidjsalazarmoreno your issue isn't related to 1.8.2 (although at some point it probably would have given you trouble). Your issue is because you have "moduleResolution": "node" in your tsconfig.json file. It looks like this causes issues when using the compiler API as we do. Only it isn't reported as a compiler error, it is an actual runtime error, so it was bubbling up before this change. This is fixable on your part for the moment by removing that from your tsconfig or overriding it in the brunch-config.js file with:

plugins: {
  brunchTypescript: {
    moduleResolution: undefined
  }
}

However, I will also make sure in future versions we strip this option out before passing them into the compiler.

@speg Your issue is similar but different. It is an error which occurs because we are compiling one module at a time and can be ignored. I'll fix that too.

@paulmillr I'm not sure if these errors are really going to provide a huge value since they don't consider the other files when they compile. So if you have a type violation within a single file, it will flag that, but if you import a function from another file and use it with incorrect types, it doesn't know about it or raise any issue with that.

Similarly, it isn't aware of any globals or anything like that, so I'll have to ignore the "Can't find name" error outright.

I'm sure we can get the compiler to consider the other files, but that would slow things down a fair bit I would imagine.

At the moment, we can remove the errors, log them without failing, or we could allow people to specify error numbers they want to ignore.

/cc @baptistedonaux

@colinbate thank you, your solution works for me, the error has gone and de import works correctly, now I can import modules from node_modules.