2017-12-27 451 views
0

我不能做:流星 - 無法使用/進口NPM包

import SimpleSchema from 'simpl-schema'; 

或導入任何其他NPM包使用此命令。我已經通過meteor npm install --save simpl-schema安裝了該軟件包。

我也試圖引入其他NPM的依賴關係,如:

import moment from 'moment'; 

因此,我認爲,我通常錯過了一些重要的是能夠爲需要NPM包在我的客戶端代碼或我使用錯誤的結構?

我得到的錯誤:

Uncaught SyntaxError: Unexpected identifier

在瀏覽器控制檯。 我將不勝感激任何幫助,謝謝!

編輯:

我已經在運行應用程序之前調用meteor npm install

如果我的代碼在服務器端的js文件這一行import moment from 'moment';,我得到以下錯誤:

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\mt-os.windows.x86_64\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 Function.run (C:...meteor\local\build\programs\server\profile.js:510:12) at C:...meteor\local\build\programs\server\boot.js:462:11

我不知道我是否安裝了巴貝爾包correcty。我認爲那裏出了問題。這是我的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" 
    } 
} 

第二個編輯:(?也許自上次更新)

好吧,這似乎是我有流星安裝和新公共管理的重大課題依賴。我不能夠創建一個新的流星項目因這個錯誤:

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\mt-os.windows.x86_64\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.

你可以在這裏檢查這個錯誤: https://github.com/meteor/meteor/issues/8585。它告訴我,由於沒有找到Git路徑,所以不能安裝Npm依賴項。

但是,重新安裝Git的解決方案並不適合我。所以,我認爲自上次流星更新以來,一般情況都是錯誤的......我現在有點卡住了。也許唯一的解決辦法是重新安裝流星或使用舊版本?我從我的電腦開始使用舊流星版本的這個項目,卸載並重新安裝babel沒有任何區別。

+0

錯誤似乎與代碼中的不同位置有關(語法錯誤),有沒有關於行,類錯誤堆棧等的任何信息? – Jankapunkt

+0

感謝您的回覆。不幸的是,我沒有任何有關特定行或任何其他信息,而不是事實,即只有在我的客戶端代碼中包含「import ...」行時纔會發生此錯誤。當我點擊chrome中的「sources」時,我可以看到'(函數(){'{''simpl-schema'; ...')將該SimpleSchema從紅色高亮顯示出來,所以它告訴我這個錯誤是因爲那麼這段代碼是否正確,或者我是否可能需要使用另一種語法或「簡單模式」路徑? – Jaybruh

+1

對此有一些想法1.您是否在運行應用程序之前調用了'meteor npm install'?這個錯誤是否也發生在服務器端?如果是這樣,請從服務器控制檯發佈錯誤堆棧。3.你確定Babel包安裝正確嗎?請發佈你的package.json – Jankapunkt

回答

0

好的,明白了!儘管我不清楚導致錯誤的原因,但我可以通過創建一個帶有--bare標誌的新流星項目來解決這個問題(所以現在我知道所有的npm依賴項都已正確安裝,以確保我可以使用'import')並複製了我的代碼到項目中。然而,比我得到另一個錯誤消息,告訴我,我的引導程序與我的jQuery版本不兼容。解決此之前,我曾在我的client/vendor文件夾,這會產生另一個錯誤

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

比我安裝刪除codemirror[email protected]再加上我在我的代碼使用所有必要的數據表NPM的依賴,以保持我的應用引導和jQuery的兼容性。現在我可以使用import SimpleSchema from 'simpl-schema'和所有其他導入,並且不會再出現錯誤。

最後,一些npm和/或包是錯誤的,最初的錯誤可以通過創建一個新的流星項目來解決。其他錯誤與bootstrap/jquery兼容性和codemirror相關。