简体   繁体   中英

How to resolve moment-timezone import issue with meteor npm

I am trying to use the moment-timezone npm package in my meteor app to no avail. If I use the atmosphere package, everything runs just fine. However I would like to get the npm package running as the atmosphere one is no longer being maintained. I have removed the atmosphere package completely from the app before trying to get it running via npm.

When I run meteor npm list --tree , towards the bottom the moment-timezone package and its dependency appear:

└─┬ moment-timezone@0.5.23
  └── moment@2.22.2

and meteor npm install gives:

audited 107 packages in 1.913s
found 0 vulnerabilities

In the file where I'm using moment-timezone I have

import moment from 'moment-timezone';

But the javascript console shows it is failing on the import of both moment and moment-timezone:

SyntaxError: Unexpected identifier 'moment'. import call expects
exactly one argument.

Following the console error, these two lines in two separate files are highlighted in red

import moment from 'moment';
import moment from 'moment-timezone';

So it looks to me that it isn't able to resolve the packages, but it appears as if they have been installed correctly and meteor npm install has worked fine.

The app is meteor 1.8

I'm out of ideas - any help would be greatly appreciated!

Cheers

In ES6 use like below

import moment from 'moment';
import 'moment-timezone';

here is you can see Timezone Support

The error 'Unexpected identifier' implies that the import lines haven't been transpiled and your browser doesn't understand them. Have you added the ecmascript atmosphere package to your project?

Once you've added it, the only import you should need is:

import moment from 'moment-timezone';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM