I am trying to setup a Firebase Cloud Functions repo to run mocha test. However, it throws the following error when I use import * as firebase from "firebase-functions-test"; or const firebase = require("firebase-functions-test")();. You can see in my code that I haven't even called the actual firebase functions yet so I think this a setup issue.
Question: What change do I need to make mocha test running for Firebase Functions testing using import syntax?
Working test code
import { assert } from "chai";
describe("Sanity Check", () => {
it("should pass", () => {
assert.equal(0, 0);
});
});
Failed Test Code using require
const test = require("firebase-functions-test")();
import { assert } from "chai";
describe("Sanity Check", () => {
it("should pass", () => {
assert.equal(0, 0);
test.cleanup();
});
});
Failed code using import
import * as firebase from "firebase-functions-test";
import { assert } from "chai";
const test = firebase();
describe("Sanity Check", () => {
it("should pass", () => {
assert.equal(0, 0);
test.cleanup();
});
});
Error for the failure
> functions# test /Users/cupidchan/temp/functions
> mocha -r ts-node/register test/**/*.spec.ts
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/encoder' is not defined by "exports" in /Users/cupidchan/temp/functions/node_modules/firebase-functions/package.json
at new NodeError (internal/errors.js:322:7)
at throwExportsNotFound (internal/modules/esm/resolve.js:322:9)
at packageExportsResolve (internal/modules/esm/resolve.js:545:3)
at resolveExports (internal/modules/cjs/loader.js:450:36)
at Function.Module._findPath (internal/modules/cjs/loader.js:490:31)
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:888:27)
at Function.Module._resolveFilename.sharedData.moduleResolveFilenameHook.installedValue [as _resolveFilename] (/Users/cupidchan/temp/functions/node_modules/#cspotcode/source-map-support/source-map-support.js:679:30)
at Function.Module._load (internal/modules/cjs/loader.js:746:27)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:93:18)
at Object.<anonymous> (/Users/cupidchan/temp/functions/node_modules/firebase-functions-test/lib/providers/firestore.js:26:19)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:93:18)
at Object.<anonymous> (/Users/cupidchan/temp/functions/node_modules/firebase-functions-test/lib/features.js:9:19)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:93:18)
at module.exports (/Users/cupidchan/temp/functions/node_modules/firebase-functions-test/lib/index.js:30:20)
at Object.<anonymous> (/Users/cupidchan/temp/functions/test/index.spec.ts:9:14)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Module.m._compile (/Users/cupidchan/temp/functions/node_modules/ts-node/src/index.ts:1371:23)
at Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Object.require.extensions.<computed> [as .ts] (/Users/cupidchan/temp/functions/node_modules/ts-node/src/index.ts:1374:12)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:93:18)
at Object.exports.requireOrImport (/Users/cupidchan/temp/functions/node_modules/mocha/lib/nodejs/esm-utils.js:56:20)
at async Object.exports.loadFilesAsync (/Users/cupidchan/temp/functions/node_modules/mocha/lib/nodejs/esm-utils.js:88:20)
at async singleRun (/Users/cupidchan/temp/functions/node_modules/mocha/lib/cli/run-helpers.js:125:3)
at async Object.exports.handler (/Users/cupidchan/temp/functions/node_modules/mocha/lib/cli/run.js:374:5)
npm ERR! Test failed. See above for more details.
package.json
{
"name": "functions",
"scripts": {
"lint": "eslint --ext .js,.ts .",
"build": "tsc",
"serve": "npm run build && firebase emulators:start --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log",
"test": "mocha -r ts-node/register test/**/*.spec.ts --reporter spec"
},
"engines": {
"node": "14"
},
"main": "lib/index.js",
"dependencies": {
"firebase-admin": "^9.8.0",
"firebase-functions": "^3.14.1"
},
"devDependencies": {
"#types/chai": "^4.2.22",
"#types/mocha": "^9.0.0",
"#types/node": "^16.11.11",
"#typescript-eslint/eslint-plugin": "^3.9.1",
"#typescript-eslint/parser": "^3.8.0",
"chai": "^4.3.4",
"eslint": "^7.6.0",
"eslint-config-google": "^0.14.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-prettier": "^4.0.0",
"esm": "^3.2.25",
"firebase-functions-test": "^0.2.3",
"mocha": "^9.1.3",
"prettier": "^2.5.0",
"ts-node": "^10.4.0",
"typescript": "^3.8.0"
},
"private": true
}
tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"noImplicitReturns": true,
"noUnusedLocals": true,
"outDir": "lib",
"sourceMap": true,
"strict": true,
"target": "es2017"
},
"compileOnSave": true,
"include": ["src", "test"]
}
This error should be resolved after specifying the latest version of the
firebase-functions, v3.16.0, and
firebase-functions-test, v0.3.3.
Related
I am newbie on Jest and I have the following issue when I execute the command
npm test
I have the following files
functions.js
const functions = {
add: (num1,num2) => num1 + num2
};
module.exports = functions;
and the functions.test.js
const functions = require('./functions');
test(`Adds 2 + 2 to equal 4`, ()=>{
expect(functions.add(2,2)).toBe(4);
});
my package.json has the following context
{
"name": "jest-tutorial",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "jest"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"jest": "^29.2.2"
}
}
I havent found a lot of resources on the internet regarding the error I just try to remove the dot (.) character from the node_modules/jest
and the output of the console (error) is below
> jest-tutorial#1.0.0 test
> jest
C:\Users\agiallelis\node_modules\jest-cli\build\run.js:129
if (error?.stack) {
^
SyntaxError: Unexpected token '.'
at wrapSafe (internal/modules/cjs/loader.js:1054:16)
at Module._compile (internal/modules/cjs/loader.js:1102:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
at Module.load (internal/modules/cjs/loader.js:986:32)
at Function.Module._load (internal/modules/cjs/loader.js:879:14)
at Module.require (internal/modules/cjs/loader.js:1026:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (C:\Users\agiallelis\node_modules\jest-cli\build\index.js:12:12)
at Module._compile (internal/modules/cjs/loader.js:1138:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
For some odd reason (i have been deployed on Heroku for around 1.5 years) my instance decided to throw a weird error regarding not finding 'mongoose' after attempting to deploy again. Everything works on my local server and my .gitignore file ignores Node Modules. This is a React.js app with Expressjs and Mongoose.
Here is my Package.json:
{
"name": "drg-coming-soon",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "webpack",
"server": "node server/index.js",
"start": "webpack && node server/index.js",
"react": "webpack -d --watch"
},
"heroku-run-build-script": true,
"author": "Randy Thomas",
"license": "ISC",
"devDependencies": {
"axios": "^0.18.0",
"babel-core": "^6.23.1",
"babel-loader": "^6.3.2",
"babel-preset-es2015": "^6.22.0",
"babel-preset-react": "^6.23.0",
"body-parser": "^1.18.3",
"express": "^4.15.0",
"jquery": "^3.1.1",
"mongoose": "^6.2.7",
"react-awesome-modal": "^2.0.5",
"request": "^2.81.0",
"webpack": "^4.28.3"
},
"dependencies": {
"axios": "^0.18.0",
"css-loader": "^2.0.1",
"dotenv": "^6.2.0",
"file-loader": "^2.0.0",
"react": "^15.4.2",
"react-autosuggest": "^9.4.3",
"react-dom": "^15.4.2",
"react-image": "^1.5.1",
"react-router": "^4.3.1",
"react-router-dom": "^4.3.1",
"react-scripts": "^2.1.1",
"style-loader": "^0.23.1",
"twilio": "^3.33.2",
"url-loader": "^1.1.2",
"mongoose": "^6.2.7",
"webpack": "^4.28.3"
}
}
Here is my webpack.config.js
const path = require('path');
const SRC_DIR = path.join(__dirname, '/client/src');
const DIST_DIR = path.join(__dirname, '/client/dist');
module.exports = {
entry: `${SRC_DIR}/index.js`,
output: {
filename: 'bundle.js',
path: DIST_DIR,
},
module: {
//changed from loaders to rules
loaders: [
{
test: /\.jsx?/,
include: SRC_DIR,
loader: 'babel-loader',
query: {
presets: [
'#babel/preset-env',
'#babel/preset-react'
],
},
},
],
},
};
Here is my Database folder:
require('dotenv').config();
const mongoose = require('mongoose');
// dev
// process.env.mongourl
mongoose.connect(process.env.mongourl)
.catch(err => console.log('Mongo connection error', err));
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', () => {
console.log('MongoDB has connected');
});
// schemas
const comingSoonSchema = ({
address: String,
desc: String,
sqft: Number,
bed: String,
bath: String,
photoLink: String,
agent: String,
price: String,
year: Number,
eta: String,
premarket: String,
status: String,
timeStamp: { type: Date, default: Date.now },
})
// models
const ComingSoon = mongoose.model('ComingSoon', comingSoonSchema);
function save(e) {
console.log(e, "SAVE FUNC");
const obj = new ComingSoon({
address: e.address,
desc: e.desc,
sqft: e.sqft,
bed: e.bed,
bath: e.bath,
photoLink: e.photoLink,
agent: e.agent,
price: e.price,
year: e.year,
eta: e.eta,
status: e.status,
premarket: e.premarket
})
obj.save();
console.log("Data saved to MongoDB Database");
}
const funcs = {
save, ComingSoon,
};
module.exports = funcs;
And lastly here is the persisting error:
2022-03-23T01:33:06.685994+00:00 heroku[web.1]: Starting process with command `npm start`
2022-03-23T01:33:07.919434+00:00 app[web.1]:
2022-03-23T01:33:07.919447+00:00 app[web.1]: > drg-coming-soon#1.0.0 start
2022-03-23T01:33:07.919448+00:00 app[web.1]: > webpack && node server/index.js
2022-03-23T01:33:07.919448+00:00 app[web.1]:
2022-03-23T01:33:07.965317+00:00 app[web.1]: One CLI for webpack must be installed. These are recommended choices, delivered as separate packages:
2022-03-23T01:33:07.965319+00:00 app[web.1]: - webpack-cli (https://github.com/webpack/webpack-cli)
2022-03-23T01:33:07.965319+00:00 app[web.1]: The original webpack full-featured CLI.
2022-03-23T01:33:07.965784+00:00 app[web.1]: We will use "npm" to install the CLI via "npm install -D".
2022-03-23T01:33:08.131129+00:00 app[web.1]: Do you want to install 'webpack-cli' (yes/no): node:internal/modules/cjs/loader:936
2022-03-23T01:33:08.131131+00:00 app[web.1]: throw err;
2022-03-23T01:33:08.131131+00:00 app[web.1]: ^
2022-03-23T01:33:08.131132+00:00 app[web.1]:
2022-03-23T01:33:08.131132+00:00 app[web.1]: Error: Cannot find module 'mongoose'
2022-03-23T01:33:08.131132+00:00 app[web.1]: Require stack:
2022-03-23T01:33:08.131133+00:00 app[web.1]: - /app/database/index.js
2022-03-23T01:33:08.131136+00:00 app[web.1]: - /app/server/index.js
2022-03-23T01:33:08.131136+00:00 app[web.1]: at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
2022-03-23T01:33:08.131137+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:778:27)
2022-03-23T01:33:08.131137+00:00 app[web.1]: at Module.require (node:internal/modules/cjs/loader:1005:19)
2022-03-23T01:33:08.131138+00:00 app[web.1]: at require (node:internal/modules/cjs/helpers:102:18)
2022-03-23T01:33:08.131138+00:00 app[web.1]: at Object.<anonymous> (/app/database/index.js:2:18)
2022-03-23T01:33:08.131139+00:00 app[web.1]: at Module._compile (node:internal/modules/cjs/loader:1103:14)
2022-03-23T01:33:08.131139+00:00 app[web.1]: at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
2022-03-23T01:33:08.131140+00:00 app[web.1]: at Module.load (node:internal/modules/cjs/loader:981:32)
2022-03-23T01:33:08.131140+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:822:12)
2022-03-23T01:33:08.131140+00:00 app[web.1]: at Module.require (node:internal/modules/cjs/loader:1005:19) {
2022-03-23T01:33:08.131141+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2022-03-23T01:33:08.131141+00:00 app[web.1]: requireStack: [ '/app/database/index.js', '/app/server/index.js' ]
2022-03-23T01:33:08.131142+00:00 app[web.1]: }
2022-03-23T01:33:08.265674+00:00 heroku[web.1]: Process exited with status 1
2022-03-23T01:33:08.447674+00:00 heroku[web.1]: State changed from starting to crashed
2022-03-23T01:32:58.202124+00:00 app[api]: Release v158 created by user bookingrlthomas#gmail.com
2022-03-23T01:32:58.202124+00:00 app[api]: Deploy ad551b5e by user bookingrlthomas#gmail.com
2022-03-23T01:33:00.927332+00:00 app[api]: Deploy ad551b5e by user bookingrlthomas#gmail.com
2022-03-23T01:33:00.927332+00:00 app[api]: Release v159 created by user bookingrlthomas#gmail.com
2022-03-23T01:33:51.331557+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=drgcomingsoonlistings.herokuapp.com request_id=fd27788b-e166-49fd-8830-b0da493e7e62 fwd="47.45.81.207" dyno= connect= service= status=503 bytes= protocol=https
2022-03-23T01:33:52.166634+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=drgcomingsoonlistings.herokuapp.com request_id=4967681e-a5a9-41b9-9129-65258f9b9983 fwd="47.45.81.207" dyno= connect= service= status=503 bytes= protocol=https
The error is most likely coming from the fact that you have mongoose in your "devDependencies". Try moving it to your "dependencies", then running npm install. You may run into the same issue with express and a few others under "devDependencies". Hope this helps.
It does not make any sense, but if mongoose is both in dev dependencies and in dependencies, heroku goes nuts. It can be ONLY in dependencies. After deleting it from dev dependencies, do npm install. It will work without any issues.
I am making a WordPress plugin that uses gulp to control all my assets and when I try to trigger the gulp-watch function it gives me this error:
C:\xampp\htdocs\testsite\wp-content\plugins\basic-plugin>gulp watch
Error: Cannot find module 'gulp-watch'
Require stack:
- C:\xampp\htdocs\testsite\wp-content\plugins\basic-plugin\gulpfile.js
- C:\xampp\htdocs\testsite\wp-content\plugins\basic-plugin\node_modules\gulp-
cli\lib\shared\require-or-import.js
- C:\xampp\htdocs\testsite\wp-content\plugins\basic-plugin\node_modules\gulp-
cli\lib\versioned\^4.0.0\index.js
- C:\xampp\htdocs\testsite\wp-content\plugins\basic-plugin\node_modules\gulp-
cli\index.js
- C:\xampp\htdocs\testsite\wp-content\plugins\basic-plugin\node_modules\gulp\
bin\gulp.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:1
5)
at Function.Module._load (internal/modules/cjs/loader.js:725:27)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (C:\xampp\htdocs\testsite\wp-content\plugins\basic-
plugin\gulpfile.js:7:13)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\xampp\\htdocs\\testsite\\wp-content\\plugins\\basic-plugin\\gulpfile
.js',
'C:\\xampp\\htdocs\\testsite\\wp-content\\plugins\\basic-plugin\\node_mod
ules\\gulp-cli\\lib\\shared\\require-or-import.js',
'C:\\xampp\\htdocs\\testsite\\wp-content\\plugins\\basic-plugin\\node_mod
ules\\gulp-cli\\lib\\versioned\\^4.0.0\\index.js',
'C:\\xampp\\htdocs\\testsite\\wp-content\\plugins\\basic-plugin\\node_mod
ules\\gulp-cli\\index.js',
'C:\\xampp\\htdocs\\testsite\\wp-content\\plugins\\basic-plugin\\node_mod
ules\\gulp\\bin\\gulp.js'
]
}
Although I have added the gulp-watch plugin and saved it in my devDependencies and I also have called it in gulpfile.js using require() method but it still gives the error MODULE NOT FOUND. I have also added my gulpfile.js and package.json file you can see it for yourselves. Here is my package.json file:
{
"name": "basic-plugin",
"version": "1.0.0",
"description": "basic wordpress custom plugin",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"js",
"gulp",
"wordpress",
"plugin"
],
"author": "Arslan Abbasi <arslanarshad321#gmail.com>",
"license": "GPL-3.0",
"devDependencies": {
"#babel/preset-env": "^7.13.8",
"babel-core": "^6.26.0",
"babel-preset-env": "^1.6.1",
"babelify": "^10.0.0",
"browser-sync": "^2.18.13",
"browserify-shim": "^3.8.14",
"gulp": "^4.0.2",
"gulp-autoprefixer": "^7.0.1",
"gulp-concat": "^2.5.2",
"gulp-if": "^3.0.0",
"gulp-notify": "^3.0.0",
"gulp-options": "^1.1.1",
"gulp-plumber": "^1.1.0",
"gulp-rename": "^2.0.0",
"gulp-sass": "^4.1.0",
"gulp-sourcemaps": "^3.0.0",
"gulp-strip-debug": "^3.0.0",
"gulp-uglify": "^3.0.0",
"gulp-uglifycss": "^1.0.9",
"vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^2.0.0"
},
"babel": {
"presets": [
"env"
]
},
"browserify": {
"transform": [
"browserify-shim"
]
},
"browser": {
"jquery": "./node_modules/jquery/dist/jquery.js"
},
"browserify-shim": {
"jquery": "$"
}
}
Here is my gulpfile.js:
var gulp = require('gulp');
var rename = require('gulp-rename');
var sass = require('gulp-sass');
var uglify = require('gulp-uglify');
var autoprefixer = require( 'gulp-autoprefixer');
var sourcemaps = require('gulp-sourcemaps');
var watch = require('gulp-watch');
var browserify = require('browserify');
var babelify = require('babelify');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var styleSRC = 'src/scss/mstyle.scss';
var styleDIST = './assets/';
var jsSRC = 'src/js/';
var jsScript = 'script.js';
var jsFiles = [jsScript];
var jsDIST = './assets/js/';
var styleWatch = 'src/scss/**/*.scss';
var jsWatch = 'src/js/**/*.js';
gulp.task('style', function(done){
return gulp.src(styleSRC)
.pipe(sourcemaps.init())
.pipe(sass({
errorLogToConsole: true,
outputStyle: 'compressed'
}) )
.on('error',console.error.bind(console))
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(rename({suffix: '.min'}))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(styleDIST));
done();
});
gulp.task('js', function(done){
jsFiles.map(function(entry){
return browserify({entries: [jsSRC+entry]})
.transform(babelify, {presets:['#babel/env']})
.bundle()
.pipe(source(entry))
.pipe(rename({extname:'.min.js'}))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(uglify())
.pipe(sourcemaps.write('./'))
.pipe( gulp.dest( jsDIST) );
});
done();
});
gulp.task('default',gulp.series(['style', 'js']));
gulp.task('watch',gulp.series(['default'], function(done){
gulp.watch(styleWatch,gulp.parallel(['style']));
gulp.watch(jsWatch,gulp.parallel(['js']));
done();
}));
Can someone please help me with what to do? I have been struggling with it for hours.
You need to add add/install gulp-watch... i dont see it in your package.json. To add it try:
npm install gulp-watch
or
yarn add gulp-watch
I am using the serverless framework to develop lambda functions in the aws cloud. Currently, I am running into an issue when including a library that I made. It seems the recommended way to do this is to either:
1) npm install <path/to/your/lib>
2) npm link and related commands
In the first situation, when using npm install ../libs, and include the module using const Libs = require('libs') , the package appears to install correctly (it is listed in the package.json). However, on uploading the service to aws or using sls invoke local -f my-func the following error is thrown:
{ Error: Cannot find module 'libs'
at Function.Module._resolveFilename (module.js:555:15)
at Function.Module._load (module.js:482:25)
at Module.require (module.js:604:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/Users/Documents/GitHub/serverless-cloud-functions/dynamodb-stream-handlers/.webpack/service/service-provider-users-archive-stream-handler.js:419:18)
at __webpack_require__ (/Users/Documents/GitHub/serverless-cloud-functions/dynamodb-stream-handlers/.webpack/service/service-provider-users-archive-stream-handler.js:20:30)
at Object.<anonymous> (/Users/Documents/GitHub/serverless-cloud-functions/dynamodb-stream-handlers/.webpack/service/service-provider-users-archive-stream-handler.js:376:16)
at __webpack_require__ (/Users/Documents/GitHub/serverless-cloud-functions/dynamodb-stream-handlers/.webpack/service/service-provider-users-archive-stream-handler.js:20:30)
at Object.defineProperty.value (/Users/Documents/GitHub/serverless-cloud-functions/dynamodb-stream-handlers/.webpack/service/service-provider-users-archive-stream-handler.js:63:18)
at Object.<anonymous> (/Users/Documents/GitHub/serverless-cloud-functions/dynamodb-stream-handlers/.webpack/service/service-provider-users-archive-stream-handler.js:66:10)
at Module._compile (module.js:660:30)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
at Module.require (module.js:604:17)
at require (internal/module.js:11:18)
at AwsInvokeLocal.invokeLocalNodeJs (/usr/local/lib/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:258:33)
at AwsInvokeLocal.invokeLocal (/usr/local/lib/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:125:19)
at AwsInvokeLocal.tryCatcher (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:512:31)
at Promise._settlePromise (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:569:18)
at Promise._settlePromise0 (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:614:10)
at Promise._settlePromises (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:693:18)
at Async._drainQueue (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:133:16)
at Async._drainQueues (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:143:10)
at Immediate.Async.drainQueues [as _onImmediate] (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:17:14)
at runCallback (timers.js:773:18)
at tryOnImmediate (timers.js:734:5)
at processImmediate [as _immediateCallback] (timers.js:711:5) code: 'MODULE_NOT_FOUND' }
Using npm link gives similar results as well. I have a hunch that the issue has to do with the fact that I'm using babel and webpack, but I'm not sure.
Here is the contents of my webpack.config.js file:
const slsw = require("serverless-webpack");
const nodeExternals = require("webpack-node-externals");
module.exports = {
entry: slsw.lib.entries,
target: "node",
externals: [nodeExternals()],
module: {
rules: [
{
test: /\.js$/,
loader: "babel-loader",
include: __dirname,
exclude: /node_modules/
}
]
},
};
Including the individual clients, instead of the overall lib seems to have solved the above error, but now I am faced with a new error.
Here is the serverless.yml file:
service: instant-response-api
plugins:
- serverless-webpack
- serverless-domain-manager
- serverless-plugin-aws-alerts
custom:
alerts:
topics:
alarm: ${file(./env.yml):${opt:stage}.ADMIN_SNS_TOPIC_ARN}
alarms:
- functionErrors
webpackIncludeModules: true
customDomain:
domainName: ${file(./env.yml):${opt:stage}.DOMAIN_NAME}
basepath: ''
stage: ${opt:stage}
createdRoute53Record: true
provider:
name: aws
runtime: nodejs6.10
region: us-west-2
stage: ${opt:stage}
environment:
${file(./env.yml):${opt:stage}}
iamRoleStatements:
- Effect: "Allow"
Action:
- dynamodb:DescribeTable
- dynamodb:Query
- dynamodb:Scan
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
- dynamodb:DescribeTable
Resource: "arn:aws:dynamodb:us-west-2:*:*"
- Effect: "Allow"
Action:
- sns:Publish
- sns:CreateTopic
Resource: "arn:aws:sns:*:*:*"
functions:
create-service-provider-number:
handler: create-service-provider-number.main
memorySize: 3008
timeout: 30
logRetentionInDays: 30
events:
- http:
path: create-service-provider-number/{serviceProviderId}
method: post
cors: true
alarms:
- functionErrors
service-provider-sms-handler:
handler: service-provider-sms-handler.main
memorySize: 3008
timeout: 30
logRetentionInDays: 30
events:
- http:
path: service-provider-sms-handler/{serviceProviderId}
method: post
cors: true
alarms:
- functionErrors
end-user-voice-handler:
handler: end-user-voice-handler.main
memorySize: 3008
timeout: 30
logRetentionInDays: 30
events:
- http:
path: end-user-voice-handler/{userId}/{propertyId}
method: post
cors: true
alarms:
- functionErrors
end-user-sms-handler:
handler: end-user-sms-handler.main
memorySize: 3008
timeout: 30
logRetentionInDays: 30
events:
- http:
path: end-user-sms-handler/{userId}/{propertyId}
method: post
cors: true
alarms:
- functionErrors
And here is package.json:
{
"name": "instant-response-api",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "jest"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"aws-sdk": "^2.177.0",
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.6.1",
"babel-preset-stage-3": "^6.24.1",,
"jest": "^22.4.2",
"jest-cli": "^22.1.4",,
"serverless-domain-manager": "^2.1.0",
"serverless-plugin-aws-alerts": "^1.2.4",
"serverless-webpack": "^4.2.0",
"webpack": "^3.10.0",
"webpack-node-externals": "^1.6.0"
},
"dependencies": {
"#google/maps": "^0.4.5",
"babel-runtime": "^6.26.0",
"query-string": "^5.0.1",
"twilioClient": "file:../libs/twilioClient",
"dynamodbClient": "file:../libs/dynamodbClient",
"snsClient": "file:../libs/snsClient"
}
}
My new error:
START RequestId: a9962b1d-21dd-11e8-bc1e-35d1e2dcfd8e Version: $LATEST
Syntax error in module 'service-provider-sms-handler': SyntaxError
async sendSms({to, from, msg}) {
^^^^^^^
SyntaxError: Unexpected identifier
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
END RequestId: a9962b1d-21dd-11e8-bc1e-35d1e2dcfd8e
REPORT RequestId: a9962b1d-21dd-11e8-bc1e-35d1e2dcfd8e Duration: 5.62 ms Billed Duration: 100 ms Memory Size: 3008 MB Max Memory Used: 22 MB
In the package.json file I have following dependencies :
"devDependencies": {
"bower": "^1.7.7",
"http-server": "^0.9.0",
"jasmine-core": "^2.4.1",
"karma": "^0.13.22",
"karma-chrome-launcher": "^0.2.3",
"karma-firefox-launcher": "^0.1.7",
"karma-jasmine": "^0.3.8",
"karma-junit-reporter": "^0.4.1",
"protractor": "^4.0.9"
}
And bower.json dependencies:
"dependencies": {
"angular": "~1.5.0",
"angular-route": "~1.5.0",
"angular-loader": "~1.5.0",
"angular-mocks": "~1.5.0",
"html5-boilerplate": "^5.3.0"
}
If I perform the command karma start karma.conf.js I'll have an error like this:
Error: Cannot find module 'jasmine-core'
at Function.Module._resolveFilename (module.js:469:15)
at Function.resolve (internal/module.js:27:19)
at initJasmine (C:\Users\Ema_Holub\AppData\Roaming\npm\node_modules\karma-jasmine\lib\index.js:8:42)
at Array.invoke (C:\Users\Ema_Holub\AppData\Roaming\npm\node_modules\karma\node_modules\di\lib\injector.js:75:15)
at Injector.get (C:\Users\Ema_Holub\AppData\Roaming\npm\node_modules\karma\node_modules\di\lib\injector.js:48:43)
at C:\Users\Ema_Holub\AppData\Roaming\npm\node_modules\karma\lib\server.js:143:20
at Array.forEach (native)
at Server._start (C:\Users\Ema_Holub\AppData\Roaming\npm\node_modules\karma\lib\server.js:142:21)
at Injector.invoke (C:\Users\Ema_Holub\AppData\Roaming\npm\node_modules\karma\node_modules\di\lib\injector.js:75:15)
at Server.start (C:\Users\Ema_Holub\AppData\Roaming\npm\node_modules\karma\lib\server.js:103:18)
at Object.exports.run (C:\Users\Ema_Holub\AppData\Roaming\npm\node_modules\karma\lib\cli.js:280:26)
at Object.<anonymous> (C:\Users\Ema_Holub\AppData\Roaming\npm\node_modules\karma\bin\karma:3:23)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
What am I doing wrong?