Skip to content

Typescript 2.9.1 strange errors with imports not getting resolved #1480

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ascott18 opened this issue Jun 5, 2018 · 4 comments
Closed

Typescript 2.9.1 strange errors with imports not getting resolved #1480

ascott18 opened this issue Jun 5, 2018 · 4 comments

Comments

@ascott18
Copy link

ascott18 commented Jun 5, 2018

Version

3.0.0-beta.15

Reproduction link

https://github.com/ascott18/vue-cli-ts291-bug

Steps to reproduce

  • yarn
  • yarn serve
  • Navigate to site, open F12 tools, observe errors:

What is expected?

Import Consts should be resolved by webpack and should function as any other import would. Instead, webpack doesn't change this import to the usual WEBPACK_IMPORTED_MODULE stuff - it stays as Consts, which is undefined in the compiled javascript.

Note that this issue also happens if the import of Consts is changed to import { Foo } from './imported-const' and the corresponding usage is changed accordingly.

What is actually happening?

vue.runtime.esm.js?2b0e:587 [Vue warn]: Error in mounted hook: "ReferenceError: Consts is not defined"

found in

---> <App> at src\App.vue
       <Root>
warn @ vue.runtime.esm.js?2b0e:587
vue.runtime.esm.js?2b0e:1737 ReferenceError: Consts is not defined
    at new DerivedFoo (App.vue?95a9:16)
    at VueComponent.mounted (App.vue?95a9:25)
    at callHook (vue.runtime.esm.js?2b0e:2917)
    at Object.insert (vue.runtime.esm.js?2b0e:4154)
    at invokeInsertHook (vue.runtime.esm.js?2b0e:5956)
    at Vue.patch [as __patch__] (vue.runtime.esm.js?2b0e:6175)
    at Vue._update (vue.runtime.esm.js?2b0e:2656)
    at Vue.updateComponent (vue.runtime.esm.js?2b0e:2784)
    at Watcher.get (vue.runtime.esm.js?2b0e:3138)
    at new Watcher (vue.runtime.esm.js?2b0e:3127)
    at mountComponent (vue.runtime.esm.js?2b0e:2791)
    at Vue.$mount (vue.runtime.esm.js?2b0e:7995)
    at eval (main.ts?cd49:8)
    at Module../src/main.ts (app.js:1387)
    at __webpack_require__ (app.js:717)
    at fn (app.js:99)
    at Object.0 (app.js:1400)
    at __webpack_require__ (app.js:717)
    at app.js:784
    at app.js:787

Typescript 2.9.1 suffers from this; downgrading to 2.8.3 fixes this error. See https://github.com/ascott18/vue-cli-ts291-bug/tree/ts-283.

If I pull the code in question out of a .vue file and into a plain .ts file and then compile it on its own with tsc, the compiled output is identical between 2.8.3 and 2.9.1. This seems to indicate that it isn't a bug specifically with Typescript, but somewhere in the toolchain's interactions with Typescript.

@LinusBorg
Copy link
Member

LinusBorg commented Jun 6, 2018

Sounds rather related to this bug with Typescript:

microsoft/TypeScript#24551

Currently I'm having an issue where I've imported a variable, and the import is being removed during transpilation. The reference still remains, but the code breaks at runtime because the import is missing.
[...]
the issue is currently occurring when an imported reference is used only in super clause of a constructor.

(emphasis by me)

You do exactly that:

import * as Consts from './imported-const'
class DerivedFoo extends BaseFoo<any> {
  constructor() { super(Consts.Foo) }
}

They already merged a fix, so I assume 2.9.2 should have a fix for this.

Thanks for the detailed reporduction by the way!

@ascott18
Copy link
Author

ascott18 commented Jun 6, 2018

That looks like exactly the issue. Thanks for taking a look! I'll let you close this one out as you see fit; not sure if you wanted to leave it open to track the bump to 2.9.2 when it comes out.

@LinusBorg
Copy link
Member

We'llleave it open to track it.

@LinusBorg
Copy link
Member

2.9.2 is out with the fix.

I'll close this, we can open a fresh issue if it persists for whatever reason

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

No branches or pull requests

2 participants