Cannot use/import npm packages


I am not able to do:

import SimpleSchema from 'simpl-schema';

or to import any other npm package with this command. I have already installed the package via meteor npm install --save simpl-schema.

I have also tried to import other npm dependencies like:

import moment from 'moment';

Therefore, I think that I generally missed something important to be able to require NPM packages in my client-side code or that I am using a wrong structure?

I get the error:

Uncaught SyntaxError: Unexpected identifier

in the browser console.
I would appreciate any help, thanks!

iirc, to use Node packages on the client, you need to install meteor-node-stubs or something like that? Also it might be worth double checking and making sure that something else isn’t throwing the error.

Thanks for the reply, but I now installed meteor-node-stubs with meteor npm install --save meteor-node-stubs and still get this error. However, I only get this error if I have the import command in my code. Any other suggestions?

It sounds more like you’re missing the ecmascript package. Can you provide the output of meteor list?

1 Like

So, you are right. I was missing the ecmascript package. But I think that I am missing several important packages or dependencies, because after I installed ecmascript, I got another error message which told me that my bootstrap is not compatible with my jquery version. I solved this issue by using meteor npm install --save jquery@2.2.4.

However, after that I am getting this error now:

Uncaught Error: Cannot find module ‘…/…/lib/codemirror’

Maybe you know which “standards” have to be installed or how to “reset” my project in a way, that I can use import and all these things? Actually, I don´t know what leads to these errors.

I have attached the output of meteor list in a screenshot.

Many thanks.

Me neither! I’ve checked a couple of those versions and they seem correct for Meteor 1.6.

You could try looking at the output of meteor list --tree and/or meteor list --tree --weak to see if some of your package dependencies need updating.

Alternatively, you could try meteor update --all-packages, which will try to update every package, including weak dependencies.

OK, got it! Although I don´t know exactly what produced the error, I could solve the issue by creating a new meteor project with the--bare flag (so now I know that all npm dependencies are installed correctly to ensure that I can use 'import') and copied my code into the project. I still got the bootstrap and jquery error, but instead of installing jquery 2.2.4, I deleted codemirror in my client/vendor folder which produces the third error

Uncaught Error: Cannot find module ‘…/…/lib/codemirror’

first and than installedjquery@2.2.4 plus all required datatable npm dependencies I use in my code. Now I can use import SimpleSchema from 'simpl-schema' and all other imports and no more errors occure.

So lastly, some npm and/or packages were wrong and the initial error could be solved by creating a new meteor project. The other errors were related to bootstrap/jquery compatibility and codeMirror.

1 Like