4

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

mpzo
  • 41
  • 1
  • 3
  • I am working on this as well and have determined that the issues isn't so much what we are trying to import but rather where. It seems that no matter what file I put the import statement into I get the error SyntaxError: import declarations may only appear at top level of a module From the running app console. We've tried startup.js and pretty much every other .js file in the client directory with the same result. Where should these go? – Peter Nunn Oct 30 '18 at 05:55

2 Answers2

1

In ES6 use like below

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

here is you can see Timezone Support

fool-dev
  • 7,671
  • 9
  • 40
  • 54
0

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';

piemonkey
  • 741
  • 3
  • 6