Set up the Serverless Framework

When I ran the command to create new project using the following, it failed

serverless install --url https://github.com/AnomalyInnovations/serverless-nodejs-starter --name notes-app-api

So I created project using the following:

sls create --template aws-nodejs --path TestService

using guidance from Serverless framework documentation.

Then as I run the command npm install, its failing saying it cant find package.json.

Can you let know whats going wrong?

Hmmm can you post the original error you got while using the instructions in the guide?

Hi,

First of all thank you for the great documentation. Its very well written. I am going through it step by step and during npm install it shows: 38499 vulnerabilities (38488 low, 2 moderate, 9 high).

jay@j-dev:~/Dev/notes-app-api$ npm install

> core-js@3.3.6 postinstall /home/jay/Dev/notes-app-api/node_modules/core-js
> node postinstall || echo "ignore"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!

The project needs your help! Please consider supporting of core-js on Open Collective or Patreon: 
> https://opencollective.com/core-js 
> https://www.patreon.com/zloirock 

Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

**added 919 packages from 631 contributors and audited 987 packages in 9.765s**
**found 38499 vulnerabilities (38488 low, 2 moderate, 9 high)**
  run `npm audit fix` to fix them, or `npm audit` for details
jay@j-dev:~/Dev/notes-app-api$ 

I did an npm audit fix and it was fixed.

jay@j-dev:~/Dev/notes-app-api$ npm audit fix 
npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
npm WARN notsup Unsupported engine for watchpack-chokidar2@2.0.0: wanted: {"node":"<8.10.0"} (current: {"node":"10.21.0","npm":"6.14.4"})
npm WARN notsup Not compatible with your version of node/npm: watchpack-chokidar2@2.0.0
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.1.2 (node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN serverless-offline@5.8.0 requires a peer of serverless@>= 1.39.0 but none is installed. You must install peer dependencies yourself.
npm WARN ts-node@8.10.2 requires a peer of typescript@>=2.7 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

added 81 packages from 35 contributors, removed 18 packages, updated 92 packages and moved 1 package in 35.059s

4 packages are looking for funding
  run `npm fund` for details

**fixed 38208 of 38499 vulnerabilities in 987 scanned packages**
**  291 vulnerabilities required manual review and could not be updated**
jay@j-dev:~/Dev/notes-app-api$ 

I am using node v10.21.0 and npm 6.14.4 running on Ubuntu 18.04.3 LTS. Is there anything else needs to done, so that there are no further issues down the line when running the notes-app?

Thanks!
Jay

The NPM audit is just something you’ll have to do every once in a while as new security vulnerabilities are found and reported. But you should be okay for now.

Great thanks! Jay!..

1 Like

Hey guys, enjoying the guide so far but I can’t get
serverless install --url https://github.com/AnomalyInnovations/serverless-nodejs-starter --name notes-app-api

to run properly for the life of me. Every time I run it I get the error:

C:\Users\olism\OneDrive\Other stuff\aws>serverless install --url https://github.com/AnomalyInnovations/serverless-nodejs-starter --name notes-app-api
internal/modules/cjs/loader.js:968
  throw err;
  ^

Error: Cannot find module '../scripts/serverless'
Require stack:
- C:\Users\olism\AppData\Roaming\npm\node_modules\serverless\bin\serverless.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:965:15)
    at Function.Module._load (internal/modules/cjs/loader.js:841:27)
    at Module.require (internal/modules/cjs/loader.js:1025:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (C:\Users\olism\AppData\Roaming\npm\node_modules\serverless\bin\serverless.js:41:1)
    at Module._compile (internal/modules/cjs/loader.js:1137:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
    at Module.load (internal/modules/cjs/loader.js:985:32)
    at Function.Module._load (internal/modules/cjs/loader.js:878:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'C:\\Users\\olism\\AppData\\Roaming\\npm\\node_modules\\serverless\\bin\\serverless.js'
  ]
}

Any help would be massively appreciated, this is on windows btw.

Hmm that’s super weird. Which version of Node, NPM, and Serverless are you using?

running into this same issue. what did you do to fix this?

@jayair @razahuss Sorry to disappoint you guys but I actualy did a clean wipe of my laptop (it needed one anyway). Although the issue was resolved when I reinstalled node and npm, I think I was using Node v12.18.3 and NPM v6.14.6. Not super helpful I know!

1 Like

The “Update Service Name” step here is a bit confusing. When I run the serverless install command, the serverless.yml file already contains the contents of the “replace with the following” box. That would be easy enough to just keep going, but the serverless.yml on my machine also has


functions:
  hello:
    handler: handler.hello
    events:
      - http:
          path: hello
          method: get

below the other content. It’s not clear whether I’m supposed to replace the entire file, or whether this content should stay there.

We added a note on the service name in this chapter. Hope that helps!

Edit: package.json was created. It was actually moved in a previous chapter to the Seed deploy. Not sure if that is supposed to be in a services folder, or the root

I had a similar issue. It seems package.json never installed with the serverless installation command. I was able to progress through the guide with no problem until deploying to Seed for the first time in this chapter: https://serverless-stack.com/chapters/deploying-through-seed.html

I ran npm init, which created the file, but I am assuming there are predefined dependencies in the file that should be added to the project. You could copy the file from the repo on git and manually create it in your root folder of the project.

1 Like

I am receiving: “-bash: serverless: command not found” when I run “serverless install --url https://github.com/AnomalyInnovations/serverless-nodejs-starter --name notes-api”

NPM v6.14.6
Node v12.18.3

1 Like

I found a fix for myself. I updated NPM to v6.14.10 and it’s working.

I am running into another problem however. I have to use sudo for every command to work. I am the admin and only login on my MacBook. Is there a way to make Terminal not require me to use sudo for everything? When I don’t it tells me I don’t have permission.

Another example,
$ npm install aws-sdk --save-dev

$ npm install uuid@7.0.3 --save

These would not work even with sudo. I had to run the following to get them to work:
$ npm install aws-sdk --save-dev --unsafe-perm=true --allow-root

$ npm install uuid@7.0.3 --save --unsafe-perm=true --allow-root

Considering my lack of knowledge I am not sure if it is “good” to use such commands.

Hmm that’s weird. You shouldn’t have to use sudo. I haven’t run into this before. Try searching around to see if you find a fix?

Hi! Can you please explain why we install uuid@7.0.3?
There is new version: 8.3.2
Is it nessesary? Can run just nmp i uuid?

Thanks!!!

$ npm install
npm ERR! code 1
npm ERR! path C:\Users\saisw\notes-api\node_modules\node-sass
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c node scripts/build.js
npm ERR! Building: C:\Program Files\nodejs\node.exe C:\Users\saisw\notes-api\node_modules\node-gyp\bin\node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp verb cli [
npm ERR! gyp verb cli ‘C:\Program Files\nodejs\node.exe’,
npm ERR! gyp verb cli ‘C:\Users\saisw\notes-api\node_modules\node-gyp\bin\node-gyp.js’,
npm ERR! gyp verb cli ‘rebuild’,
npm ERR! gyp verb cli ‘–verbose’,
npm ERR! gyp verb cli ‘–libsass_ext=’,
npm ERR! gyp verb cli ‘–libsass_cflags=’,
npm ERR! gyp verb cli ‘–libsass_ldflags=’,
npm ERR! gyp verb cli ‘–libsass_library=’
npm ERR! gyp verb cli ]
npm ERR! gyp info using node-gyp@3.8.0
npm ERR! gyp info using node@15.5.0 | win32 | x64
npm ERR! gyp verb command rebuild []
npm ERR! gyp verb command clean []
npm ERR! gyp verb clean removing “build” directory
npm ERR! gyp verb command configure []
npm ERR! gyp verb check python checking for Python executable “c:\python27\python.exe” in the PATH
npm ERR! gyp verb which failed Error: not found: c:\python27\python.exe
npm ERR! gyp verb which failed at getNotFoundError (C:\Users\saisw\notes-api\node_modules\node-gyp\node_modules\which\which.js:13:12)
npm ERR! gyp verb which failed at F (C:\Users\saisw\notes-api\node_modules\node-gyp\node_modules\which\which.js:68:19)
npm ERR! gyp verb which failed at E (C:\Users\saisw\notes-api\node_modules\node-gyp\node_modules\which\which.js:80:29)
npm ERR! gyp verb which failed at C:\Users\saisw\notes-api\node_modules\node-gyp\node_modules\which\which.js:89:16
npm ERR! gyp verb which failed at C:\Users\saisw\notes-api\node_modules\isexe\index.js:42:5
npm ERR! gyp verb which failed at C:\Users\saisw\notes-api\node_modules\isexe\windows.js:36:5
npm ERR! gyp verb which failed at FSReqCallback.oncomplete (node:fs:199:21)
npm ERR! gyp verb which failed c:\python27\python.exe Error: not found: c:\python27\python.exe
npm ERR! gyp verb which failed at getNotFoundError (C:\Users\saisw\notes-api\node_modules\node-gyp\node_modules\which\which.js:13:12)
npm ERR! gyp verb which failed at F (C:\Users\saisw\notes-api\node_modules\node-gyp\node_modules\which\which.js:68:19)
npm ERR! gyp verb which failed at E (C:\Users\saisw\notes-api\node_modules\node-gyp\node_modules\which\which.js:80:29)
npm ERR! gyp verb which failed at C:\Users\saisw\notes-api\node_modules\node-gyp\node_modules\which\which.js:89:16
npm ERR! gyp verb which failed at C:\Users\saisw\notes-api\node_modules\isexe\index.js:42:5
npm ERR! gyp verb which failed at C:\Users\saisw\notes-api\node_modules\isexe\windows.js:36:5
npm ERR! gyp verb which failed at FSReqCallback.oncomplete (node:fs:199:21) {
npm ERR! gyp verb which failed }

How to solve the Pyhton2 isn’t found issue?

I think there was a major change in their formats. So we forced it to the version that we know works.

Make sure to use latest version of serverless-bundle in your package.json.