出现以下错误:
(function (exports, require, module, __filename, __dirname) { import {decryptPassword} from "../functions/createNewUser";
^
SyntaxError: Unexpected token {
at new Script (vm.js:79:7)
at createScript (vm.js:251:10)
at Object.runInThisContext (vm.js:303:10)
at Module._compile (internal/modules/cjs/loader.js:657:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
这只是在尝试使用Mocha在本地执行测试时发生的。 这是我的tsconfig文件:
{
"compilerOptions": {
"module": "commonjs",
"noImplicitReturns": true,
"strictPropertyInitialization": false,
"noImplicitAny": false,
"strictNullChecks": false,
"noUnusedLocals": false,
"outDir": "lib",
"sourceMap": true,
"strict": true,
"target": "es2015",
"allowJs": true
},
"compileOnSave": true,
"include": [
"src"
],
"exclude": ["node_modules", "dist"]
}
和我的package.json:
{
"name": "functions",
"scripts": {
"lint": "tslint --project tsconfig.json",
"build": "tsc",
"serve": "npm run build && firebase serve --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"main": "lib/index.js",
"dependencies": {
"@google-cloud/storage": "^2.4.2",
"@types/mocha": "^5.2.6",
"bignumber.js": "^8.1.1",
"canvas": "^2.3.1",
"coinpayments": "^2.0.3",
"crypto-js": "^3.1.9-1",
"firebase-admin": "~7.0.0",
"firebase-functions": "^2.2.0",
"jimp": "^0.6.0",
"nodemailer": "^5.1.1",
"qrcanvas": "^3.0.3",
"secure-compare": "^3.0.1"
},
"devDependencies": {
"chai": "^4.2.0",
"mocha": "^6.0.2",
"tslint": "^5.13.1",
"typescript": "^3.2.2"
},
"private": true,
"version": "1.0.0",
"directories": {
"lib": "lib"
},
"author": "",
"license": "ISC",
"description": ""
}
对WebStorm进行Im测试并部署到firebase函数。 当我部署它时,它可以完美地运行在firebase函数中。
我找到的大多数答案都让我添加了Babel,但是如果它可以在生产环境中运行,却又为什么在运行测试时不能运行?