Skip to content
This repository has been archived by the owner on Jun 27, 2018. It is now read-only.

Fix TypeError: Cannot read property 'text' of undefined error. #47

Closed
wants to merge 2 commits into from

Conversation

heavenshell
Copy link

TL;DR

Fix TypeError: Cannot read property 'text' of undefined error.

Detail

When importing relative path like following, typescript-simple raised exception.

  • https://github.com/9renpoto/ts/blob/fix/filename/test/index.test.ts#L1

    TypeError: Cannot read property 'text' of undefined
        at TypeScriptSimple.toJavaScript (/tmp/src/ts/node_modules/typescript-simple/index.js:162:28)
        at TypeScriptSimple.compile (/tmp/src/ts/node_modules/typescript-simple/index.js:71:25)
        at Object.loadTypeScript (/tmp/src/ts/node_modules/espower-typescript/index.js:19:22)
    

Actual behavior

service.getEmitOutput(fileName) returns relative path and absorute path.

eg.
#: see also power-assert-js/espower-typescript#16 (comment)

/tmp/src/sample/test.ts

import {test} from './dep'

test()

/tmp/src/sample/dep.ts

export function test() {
    console.log('from ts')
}
  • service.getEmitOutput('test.ts') returns relative path
    • test.js
  • service.getEmitOutput('dep.ts') returns absolute path
    • /tmp/src/sample/deps.js

So, this line compared relative path(outputFileName) with absolute path(file.name) and returns undefined.

Solution

Convert relative path to absolute path.

PoC

Please see our sample project.

  1. git clone https://github.com/9renpoto/ts.git
  2. git checkout fix/filename
  3. npm install
  4. npm test

note

package.json's typescript-simple pointed to our PR branch.

If you delete this line, exception would raised.

Misc

This PR would also solve following issue.

Please check and include this PR.

Thank you.

@teppeis
Copy link
Owner

teppeis commented Oct 24, 2016

@heavenshell Thanks!
Your patch didn't fix this issue in Windows, but I released it with "known issues" in v5.0.3.

@heavenshell
Copy link
Author

@teppeis Thank you for solving this issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants