Cannot use/import npm packages in Meteor

meteor npm import npm-install simple-schema

512 观看


98 作者的声誉

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 have called meteor npm install before running the app.

If I code this line import moment from 'moment'; on a server side js-file, I get the following error:

app\server\startup\profilemanagement.js:1 (function(NPM,Assets){(function(){import moment from 'moment';

SyntaxError: Unexpected token import at C:...meteor\local\build\programs\server\boot.js:392:18 at Array.forEach () at Function..each..forEach (C:...meteor\packages\meteor-tool\1.6.0:1\\dev_bundle\server-lib\node_modules\underscore\underscore.js:79:11) at C:...meteor\local\build\programs\server\boot.js:220:5 at C:...meteor\local\build\programs\server\boot.js:463:5 at (C:...meteor\local\build\programs\server\profile.js:510:12) at C:...meteor\local\build\programs\server\boot.js:462:11

I am not sure if I installed the babel packages correctly. I think something went wrong there. Here is my package.json:

  "dependencies": {
    "abbrev": "^1.1.0",
    "addressparser": "^1.0.1",
    "ajv": "^5.2.2",
    "ansi-regex": "^3.0.0",
    "aproba": "^1.2.0",
    "are-we-there-yet": "^1.1.4",
    "asn1": "^0.2.3",
    "assert-plus": "^1.0.0",
    "asynckit": "^0.4.0",
    "aws-sign2": "^0.7.0",
    "aws4": "^1.6.0",
    "babel-runtime": "^6.26.0",
    "balanced-match": "^1.0.0",
    "bcrypt": "^1.0.3",
    "bcrypt-pbkdf": "^1.0.1",
    "block-stream": "0.0.9",
    "boom": "^5.2.0",
    "brace-expansion": "^1.1.8",
    "buildmail": "^4.0.1",
    "caseless": "^0.12.0",
    "chart.js": "^2.7.0",
    "chartjs-color": "^2.2.0",
    "cloudinary": "^1.9.0",
    "co": "^4.6.0",
    "code-point-at": "^1.1.0",
    "color-convert": "^1.9.0",
    "color-name": "^1.1.3",
    "combined-stream": "^1.0.5",
    "concat-map": "0.0.1",
    "console-control-strings": "^1.1.0",
    "core-js": "^2.5.1",
    "core-util-is": "^1.0.2",
    "cryptiles": "^3.1.2",
    "dashdash": "^1.14.1",
    "debug": "^3.0.1",
    "deep-extend": "^0.5.0",
    "delayed-stream": "^1.0.0",
    "delegates": "^1.0.0",
    "ecc-jsbn": "^0.1.1",
    "extend": "^3.0.1",
    "extsprintf": "^1.3.0",
    "fast-deep-equal": "^1.0.0",
    "fontawesome": "^4.7.2",
    "forever-agent": "^0.6.1",
    "form-data": "^2.3.1",
    "fs.realpath": "^1.0.0",
    "fstream": "^1.0.11",
    "fstream-ignore": "^1.0.5",
    "gauge": "^2.7.4",
    "getpass": "^0.1.7",
    "glob": "^7.1.2",
    "graceful-fs": "^4.1.11",
    "har-schema": "^2.0.0",
    "har-validator": "^5.0.3",
    "has-unicode": "^2.0.1",
    "hawk": "^6.0.2",
    "hoek": "^4.2.0",
    "http-signature": "^1.2.0",
    "iconv-lite": "^0.4.19",
    "inflight": "^1.0.6",
    "inherits": "^2.0.3",
    "ini": "^1.3.4",
    "is-fullwidth-code-point": "^2.0.0",
    "is-typedarray": "^1.0.0",
    "isarray": "^2.0.2",
    "isstream": "^0.1.2",
    "jasny-bootstrap": "^3.1.3",
    "jodid25519": "^1.0.2",
    "jsbn": "^1.1.0",
    "json-schema": "^0.2.3",
    "json-schema-traverse": "^0.3.1",
    "json-stable-stringify": "^1.0.1",
    "json-stringify-safe": "^5.0.1",
    "jsonify": "0.0.0",
    "jsprim": "^1.4.1",
    "libbase64": "^0.2.0",
    "libmime": "^3.1.0",
    "libqp": "^1.1.0",
    "lodash": "^4.17.4",
    "mailcomposer": "^4.0.2",
    "meteor-node-stubs": "^0.2.11",
    "mime-db": "^1.30.0",
    "mime-types": "^2.1.17",
    "minimatch": "^3.0.4",
    "minimist": "^1.2.0",
    "mkdirp": "^0.5.1",
    "moment": "^2.18.1",
    "ms": "^2.0.0",
    "nan": "^2.7.0",
    "node-pre-gyp": "^0.6.37",
    "nodemailer": "^4.1.0",
    "nodemailer-fetch": "^2.1.0",
    "nodemailer-shared": "^2.0.0",
    "nopt": "^4.0.1",
    "npmlog": "^4.1.2",
    "number-is-nan": "^1.0.1",
    "oauth-sign": "^0.8.2",
    "object-assign": "^4.1.1",
    "object-inspect": "^1.3.0",
    "object-keys": "^1.0.11",
    "once": "^1.4.0",
    "os-homedir": "^1.0.2",
    "os-tmpdir": "^1.0.2",
    "osenv": "^0.1.4",
    "path-is-absolute": "^1.0.1",
    "path-parse": "^1.0.5",
    "performance-now": "^2.1.0",
    "process-nextick-args": "^1.0.7",
    "punycode": "^2.1.0",
    "q": "^1.5.0",
    "qs": "^6.5.1",
    "rc": "^1.2.1",
    "readable-stream": "^2.3.3",
    "regenerator-runtime": "^0.11.0",
    "request": "^2.82.0",
    "resolve": "^1.4.0",
    "resumer": "0.0.0",
    "rimraf": "^2.6.2",
    "safe-buffer": "^5.1.1",
    "semver": "^5.4.1",
    "set-blocking": "^2.0.0",
    "signal-exit": "^3.0.2",
    "sntp": "^2.0.2",
    "sshpk": "^1.13.1",
    "string-width": "^2.1.1",
    "string.prototype.trim": "^1.1.2",
    "string_decoder": "^1.0.3",
    "stringstream": "0.0.5",
    "strip-ansi": "^4.0.0",
    "strip-json-comments": "^2.0.1",
    "sweetalert": "^1.1.3",
    "tape": "^4.8.0",
    "tar": "^4.0.1",
    "tar-pack": "^3.4.0",
    "through": "^2.3.8",
    "tough-cookie": "^2.3.2",
    "tunnel-agent": "^0.6.0",
    "tweetnacl": "^1.0.0",
    "uid-number": "0.0.6",
    "util-deprecate": "^1.0.2",
    "uuid": "^3.1.0",
    "verror": "^1.10.0",
    "wide-align": "^1.1.2",
    "wow.js": "^1.2.2",
    "wrappy": "^1.0.2",
    "yallist": "^3.0.2"

Second edit

It seems to be that (maybe since the last update?) I have a major issue with the meteor installation and its npm dependencies. I am not able to create a new meteor project due to this error:

Error: Error: Could not install npm dependencies for test-packages: Command failed: C:\WINDOWS\system32\cmd.exe /c C:\Users...\AppData\Local.meteor\packages\meteor-tool\1.6.0._1\\dev_bundle\bin\npm.cmd install npm ERR! code ENOGIT npm ERR! No git binary found in $PATH npm ERR! npm ERR! Failed using git. npm ERR! Please check if you have git installed and in your PATH.

You can check this error here: It tells that me that no Npm dependencies can be installed because of not finding the Git-path.

However, the solutiuon to reinstall Git did not work for me. So, I think something went generally wrong since the last meteor update. Maybe the only solution is to reinstall meteor completely or use an older version? I started this project from my computer with an older meteor version and uninstalling and reinstalling Babel did not make any difference.

作者: Jaybruh 的来源 发布者: 2017 年 12 月 27 日

回应 (1)


98 作者的声誉

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. However, than I got another error message which told me that my bootstrap is not compatible with my jquery version. Before solving this, I had to delete codemirror in my client/vendor folder, which produces another error

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

Than I installed jquery@2.2.4 plus all required datatable npm dependencies I use in my code to keep the compatibility of my applied bootstrap and jquery. 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.

作者: Jaybruh 发布者: 03.01.2018 04:38