TypeScript - Global import doesn't work for MomentJS
up vote
0
down vote
favorite
TypeScript provides an option to define global external modules. For example, if I have jQuery library loaded externally, I can set up global definition without including it's duplicate into TypeScript bundle. But when I try to do the same for 'moment' module, compiler doesn't import it's typing.
Here is my content of tsconfig.json
, compilerOptions
section
"compilerOptions": {
"outDir": "../out-tsc/app",
"module": "es2015",
"types": ["jquery", "moment"]
}
Here is code fragment that uses these definitions:
console.log($);
console.log(moment); // error TS2304: Cannot find name 'moment'
So it works fine for jQuery but not for MomentJS. I also have @types/jquery
and moment
added to package.json
and installed into node_modules
.
I know it's possible to use ES6 import syntax but it will include it into a bundle and I want to avoid it because it's already loaded in another place of the app.
typescript webpack momentjs
add a comment |
up vote
0
down vote
favorite
TypeScript provides an option to define global external modules. For example, if I have jQuery library loaded externally, I can set up global definition without including it's duplicate into TypeScript bundle. But when I try to do the same for 'moment' module, compiler doesn't import it's typing.
Here is my content of tsconfig.json
, compilerOptions
section
"compilerOptions": {
"outDir": "../out-tsc/app",
"module": "es2015",
"types": ["jquery", "moment"]
}
Here is code fragment that uses these definitions:
console.log($);
console.log(moment); // error TS2304: Cannot find name 'moment'
So it works fine for jQuery but not for MomentJS. I also have @types/jquery
and moment
added to package.json
and installed into node_modules
.
I know it's possible to use ES6 import syntax but it will include it into a bundle and I want to avoid it because it's already loaded in another place of the app.
typescript webpack momentjs
Maybe this question can be useful.
– VincenzoC
Nov 21 at 19:20
No, it's a different case
– Random
Nov 22 at 7:18
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
TypeScript provides an option to define global external modules. For example, if I have jQuery library loaded externally, I can set up global definition without including it's duplicate into TypeScript bundle. But when I try to do the same for 'moment' module, compiler doesn't import it's typing.
Here is my content of tsconfig.json
, compilerOptions
section
"compilerOptions": {
"outDir": "../out-tsc/app",
"module": "es2015",
"types": ["jquery", "moment"]
}
Here is code fragment that uses these definitions:
console.log($);
console.log(moment); // error TS2304: Cannot find name 'moment'
So it works fine for jQuery but not for MomentJS. I also have @types/jquery
and moment
added to package.json
and installed into node_modules
.
I know it's possible to use ES6 import syntax but it will include it into a bundle and I want to avoid it because it's already loaded in another place of the app.
typescript webpack momentjs
TypeScript provides an option to define global external modules. For example, if I have jQuery library loaded externally, I can set up global definition without including it's duplicate into TypeScript bundle. But when I try to do the same for 'moment' module, compiler doesn't import it's typing.
Here is my content of tsconfig.json
, compilerOptions
section
"compilerOptions": {
"outDir": "../out-tsc/app",
"module": "es2015",
"types": ["jquery", "moment"]
}
Here is code fragment that uses these definitions:
console.log($);
console.log(moment); // error TS2304: Cannot find name 'moment'
So it works fine for jQuery but not for MomentJS. I also have @types/jquery
and moment
added to package.json
and installed into node_modules
.
I know it's possible to use ES6 import syntax but it will include it into a bundle and I want to avoid it because it's already loaded in another place of the app.
typescript webpack momentjs
typescript webpack momentjs
asked Nov 21 at 18:43
Random
1,86511128
1,86511128
Maybe this question can be useful.
– VincenzoC
Nov 21 at 19:20
No, it's a different case
– Random
Nov 22 at 7:18
add a comment |
Maybe this question can be useful.
– VincenzoC
Nov 21 at 19:20
No, it's a different case
– Random
Nov 22 at 7:18
Maybe this question can be useful.
– VincenzoC
Nov 21 at 19:20
Maybe this question can be useful.
– VincenzoC
Nov 21 at 19:20
No, it's a different case
– Random
Nov 22 at 7:18
No, it's a different case
– Random
Nov 22 at 7:18
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
var moment;
At the top of your file.
it won't work for a huge project, and I definitely don't want to add it to every single file
– Random
Nov 22 at 9:42
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
var moment;
At the top of your file.
it won't work for a huge project, and I definitely don't want to add it to every single file
– Random
Nov 22 at 9:42
add a comment |
up vote
0
down vote
var moment;
At the top of your file.
it won't work for a huge project, and I definitely don't want to add it to every single file
– Random
Nov 22 at 9:42
add a comment |
up vote
0
down vote
up vote
0
down vote
var moment;
At the top of your file.
var moment;
At the top of your file.
answered Nov 22 at 7:59
MrAleister
429210
429210
it won't work for a huge project, and I definitely don't want to add it to every single file
– Random
Nov 22 at 9:42
add a comment |
it won't work for a huge project, and I definitely don't want to add it to every single file
– Random
Nov 22 at 9:42
it won't work for a huge project, and I definitely don't want to add it to every single file
– Random
Nov 22 at 9:42
it won't work for a huge project, and I definitely don't want to add it to every single file
– Random
Nov 22 at 9:42
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53418665%2ftypescript-global-import-doesnt-work-for-momentjs%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Maybe this question can be useful.
– VincenzoC
Nov 21 at 19:20
No, it's a different case
– Random
Nov 22 at 7:18