Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Exported typings are not a module #297

Closed
park9140 opened this issue Mar 23, 2016 · 12 comments
Closed

Exported typings are not a module #297

park9140 opened this issue Mar 23, 2016 · 12 comments

Comments

@park9140
Copy link

Exported external package typings file '**/node_modules/zone.js/dist/zone.js.d.ts' is not a module. Please contact the package author to update the package definition.

It appears that the typescript build is not outputting a module in it's definitions output.

@park9140 park9140 changed the title Exprted typings are not a module Exported typings are not a module Mar 23, 2016
@park9140
Copy link
Author

This appears to be because the core file being built is not built as an external module. You need to have at least one import or export to create the external module.

@Nek-
Copy link

Nek- commented Mar 24, 2016

I'm having same issue @park9140 did you fixed it ?

If I don't import 'zone.js' my code does not work but if I do I get this error...

@park9140
Copy link
Author

@Nek- This works for now.

declare module 'zone.js/dist/zone' {
    export var Zone; // this doesn't actually do anything just makes the compiler not complain about the empty module
}
declare module 'zone.js/dist/long-stack-trace-zone' {
    export var Zone; // this doesn't actually do anything just makes the compiler not complain about the empty module
}
import 'zone.js/dist/zone';
import 'zone.js/dist/long-stack-trace-zone';

long-stack-trace-zone is necessary because I am using angular 2.

@Nek-
Copy link

Nek- commented Mar 24, 2016

@park9140 using your code generate a different error:

src-js/app/main.ts(4,16): error TS2664: Invalid module name in augmentation, module 'zone.js/dist/zone' cannot be found.
src-js/app/main.ts(7,16): error TS2664: Invalid module name in augmentation, module 'zone.js/dist/long-stack-trace-zone' cannot be found.

But still an error.

@park9140
Copy link
Author

@Nek- One thing I forgot to mention that may cause a problem.

The first part

declare module 'zone.js/dist/zone' {
    export var Zone; // this doesn't actually do anything just makes the compiler not complain about the empty module
}
declare module 'zone.js/dist/long-stack-trace-zone' {
    export var Zone; // this doesn't actually do anything just makes the compiler not complain about the empty module
}

I have a in a separate .d.ts ambient definition. I'm not sure if those declares have to be in a .d.ts file. Also I'm using typescript 1.8.9.

In addition I don't every import 'zone.js' directly anymore.

@Nek-
Copy link

Nek- commented Mar 24, 2016

My bad ! I added a main.d.ts. It works like a charm. Thank you so much.

@Nek-
Copy link

Nek- commented Mar 24, 2016

@park9140 well, I still get an error related to zone.js. I don't know why. But this is not critical (the app works)

Anyway here is the message:

Uncaught TypeError: Cannot read property 'cancelTask' of undefined

@sebilasse
Copy link

@Nek- Getting exactly the same error, also for other modules!
Is main.ts the file where you import the zone.js stuff? Why do we need a d.ts now if it is already TS ?

@Nek-
Copy link

Nek- commented Apr 17, 2016

@sebilasse idk why TS is asking for a d.ts when it's already in TS :/. But yes I put the fix in my main.ts file.

@alexeagle
Copy link
Contributor

@robwormald discussed this with @mhevery this week, the reasoning for this is that zones are considered a polyfill, so you're expected to treat zone.js as an ambient dependency. Include zone.js.d.ts as an input to the typescript compilation, or use a ///<reference path=""/> to bring it into the compiler.

Importing from it is not the suggested pattern, as that produces a value-side expression in the JS emit asking the module loader to load zone, and instead it should be included as a browser polyfill before the module loader starts.

It's also tricky to get the right order - if you load zone.js after the module loader has started up, then the module loader or any previously loaded modules may hold a reference to un-patched async primitives, which will not be zone-aware.

Closing as WAI, but please let me know if there's something we could do better here. Maybe import * as zone from 'zone.js'; should bring some symbols into scope?

@sap9433
Copy link

sap9433 commented Apr 25, 2016

declare module 'zone.js/dist/zone' { export var Zone; // this doesn't actually do anything just makes the compiler not complain about the empty module }
doesn't work , getting . Invalid module name in augmentation, module 'zone.js/dist/zone' cannot be found, though i vave zone.js module inside node_modeles

@rahmanusta
Copy link

Hello, which version fixes this issue ? I removed the typings file in zone.js and installed typings with typings install dt~zone.js --save --global and it solves the issue, but there should be a way without workaround.

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

No branches or pull requests

6 participants