-
Notifications
You must be signed in to change notification settings - Fork 12k
importing jquery as a global library causes typescript code importing jquery to transpile as a blank object #2923
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
Comments
@shahmirn can you try just accessing jquery as a global rather then importing it and see if that works? as script added in the angular-cli.json is added as a global. |
Related to #2760 |
I don't think you can use aliases like Can you try changing it to |
Currently it kinda sucks if you need to use a lib both as a global and as an import. I haven't had the time to look at it, and tbh don't even know if there is a good solution. Even if hypothetically we fixed things and you wouldn't get an empty object, you'd never get the same global object either. And this is very important for stuff like jquery plugins... you need the same instance of jquery everywhere. So currently I think the workaround is that, when using a lib as a global and as an import, to:
This way you'll just get the one in |
Used the approach with declaration in typings.d.ts - but I had to use
But - unfortunatley Tests referencing $ or jquery are failing now. If I Import via Import * as $ from ... it is working, but then the running app is failing.
Any idea on how to make jquery known to Karma? |
I have no clue how the Angular CLI injects the Based on how you describe what works for you, I'm guessing you added jQuery to Note that |
Closing in favor of #2141 (same issue) |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
OS?
Versions.
angular-cli: 1.0.0-beta.18
node: 4.4.5
os: win32 x64
Repro steps.
add "../node_modules/jquery/dist/jquery.js" to angular-cli.json
Have a typescript file import * as $ from "jquery";
The log given by the failure.
Results in code in main.js like:
var $ = webpack_require(209);
Pasting webpack_require(209) in the browser's console results in it returning Object {}
Mention any other details that might be useful.
The text was updated successfully, but these errors were encountered: