Skip to content

Project fails to compile after adding moment library and its typings to the project #273

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
kovax opened this issue Mar 3, 2016 · 7 comments

Comments

@kovax
Copy link

kovax commented Mar 3, 2016

I have done the following list of commands using the [email protected] on windows and linux. The last ng serve command throws the "Cannot find namespace 'moment'" error.

ng new ng2cli-moment
cd ng2cli-moment/
ng serve
npm i moment --save
ng serve
typings install moment --ambient --save
ng serve

Livereload server on http://localhost:49152
Serving on http://localhost:4200/
[DiffingTSCompiler]: Typescript found the following errors:
  c:/Users/kovax/workspace/ng2cli-moment/typings/browser/ambient/moment/moment.d.ts (9, 21): Cannot find namespace 'moment'.
Error: [DiffingTSCompiler]: Typescript found the following errors:
  c:/Users/kovax/workspace/ng2cli-moment/typings/browser/ambient/moment/moment.d.ts (9, 21): Cannot find namespace 'moment'.
    at DiffingTSCompiler.doFullBuild (c:\Users\kovax\workspace\ng2cli-moment\node_modules\angular-cli\lib\broccoli\broccoli-typescript.js:202:29)
    at DiffingTSCompiler.rebuild (c:\Users\kovax\workspace\ng2cli-moment\node_modules\angular-cli\lib\broccoli\broccoli-typescript.js:101:18)
    at DiffingPluginWrapper.rebuild (c:\Users\kovax\workspace\ng2cli-moment\node_modules\angular-cli\lib\broccoli\diffing-broccoli-plugin.js:87:45)
    at c:\Users\kovax\workspace\ng2cli-moment\node_modules\angular-cli\node_modules\angular-cli\node_modules\broccoli\lib\api_compat.js:42:21
    at lib$rsvp$$internal$$tryCatch (c:\Users\kovax\workspace\ng2cli-moment\node_modules\angular-cli\node_modules\angular-cli\node_modules\rsvp\dist\rsvp.js:1036:16)
    at lib$rsvp$$internal$$invokeCallback (c:\Users\kovax\workspace\ng2cli-moment\node_modules\angular-cli\node_modules\angular-cli\node_modules\rsvp\dist\rsvp.js:1048:17)
    at c:\Users\kovax\workspace\ng2cli-moment\node_modules\angular-cli\node_modules\angular-cli\node_modules\rsvp\dist\rsvp.js:331:11
    at lib$rsvp$asap$$flush (c:\Users\kovax\workspace\ng2cli-moment\node_modules\angular-cli\node_modules\angular-cli\node_modules\rsvp\dist\rsvp.js:1198:9)
    at nextTickCallbackWith0Args (node.js:433:9)
    at process._tickCallback (node.js:362:13)
@jkuri
Copy link
Contributor

jkuri commented Mar 3, 2016

Hi. Please try to install moment-node typings as well and report if it works. Btw, you will need to restart the server after installing new typings.

@jkuri jkuri changed the title Project fails to compile after adding monet library and its typings to the project Project fails to compile after adding moment library and its typings to the project Mar 3, 2016
@kovax
Copy link
Author

kovax commented Mar 3, 2016

I am unable to install moment-node (I am pretty new to js/ts development) :

$ typings install moment-node --save --ambient
typings ERR! message Unable to find "moment-node" in the registry. If you can contribute this type definition, please help us: https://github.com/typings/registry
typings ERR! cwd c:\Users\kovax\workspace\ng2cli-moment
typings ERR! system Windows_NT 6.1.7601
typings ERR! command "c:\\Program Files (x86)\\nodejs\\node.exe" "c:\\Users\\kovax\\AppData\\Roaming\\npm\\node_modules\\typings\\dist\\bin\\typings-install.js" "moment-node" "--save" " --ambient"
typings ERR! node -v v5.2.0
typings ERR! typings -v 0.6.8
´´´

@jkuri
Copy link
Contributor

jkuri commented Mar 3, 2016

typings install github:DefinitelyTyped/DefinitelyTyped/moment/moment-node.d.ts#b090bcf9ba9f756ec8ff53e7707269729172a325 --ambient --save

Then import moment in your .ts file like

import * as moment_ from 'moment';
const moment: moment.MomentStatic = (<any>moment_)['default'] || moment_;

After this you should have moment working.

@kovax
Copy link
Author

kovax commented Mar 3, 2016

Thanks a lot This made the project compile!

@CristyTarantino
Copy link

Hi. Still having the same issue. Tried to do
typings install github:DefinitelyTyped/DefinitelyTyped/moment/moment-node.d.ts#b090bcf9ba9f756ec8ff53e7707269729172a325 --ambient --save
but I get
node Unable to find "moment-node" ("npm") in the registry. Did you want to try searching another source? Also, if you want contribute these typings, please help us: https://github.com/typings/registry Can anybody help?

@martinsvb
Copy link

Hello, --ambient was changed to --global parameter

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 5, 2019
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

4 participants