serverless: Postinstall script installation fails when installing locally

This is a Bug Report

Description

I know a correct way to install globally using npm install serverless - g, but when installing locally in own project with npm install serverless --save, an error occurs during execution of postinstall.js.

Is this bug? or does it mean sls has not supported for installing locally?

step to reproduce

  • Create directory with mkdir sls-project && cd sls-project
  • Run npm init
  • Run npm install serverless --save, and you will see the following error
$npm install serverless --save
npm WARN registry Unexpected warning for https://registry.npmjs.org/: Miscellaneous Warning EINTEGRITY: sha1-F2n0tVHu3OQZ8FBd6uLiZ2NULTc= integrity checksum failed when using sha1: wanted sha1-F2n0tVHu3OQZ8FBd6uLiZ2NULTc= but got sha512-0TZ20a+xcIl4u0+Mj5xDH2yOWdmQiXlKf9Hm+TgDXjTMsEYb+gDrmb8e8UNAzMCitX8NBqG4Z/FUQIyzv/R1JQ==. (2982 bytes)

> serverless@1.15.3 postinstall /Users/horike/src/sls-project/node_modules/serverless
> node ./scripts/postinstall.js

module.js:471
    throw err;
    ^

Error: Cannot find module '/Users/horike/src/sls-project/node_modules/serverless/node_modules/tabtab/src/cli.js'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:509:3
module.js:471
    throw err;
    ^

Error: Cannot find module '/Users/horike/src/sls-project/node_modules/serverless/node_modules/tabtab/src/cli.js'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:509:3

> spawn-sync@1.0.15 postinstall /Users/horike/src/sls-project/node_modules/spawn-sync
> node postinstall

npm WARN saveError ENOENT: no such file or directory, open '/Users/horike/src/sls-project/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '/Users/horike/src/sls-project/package.json'
npm WARN sls-project No description
npm WARN sls-project No repository field.
npm WARN sls-project No README data
npm WARN sls-project No license field.

+ serverless@1.15.3
added 210 packages in 23.298s

Similar or dependent issues:

Additional Data

  • node version: 6.10.2
  • npm version: 5.0.3
  • Serverless Framework Version you’re using:1.15.3
  • Operating System: macOS 10.11.6
  • Stack Trace: above
  • Provider Error messages: above

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 17 (10 by maintainers)

Commits related to this issue

Most upvoted comments

npm install -g serverless/serverless should work for now for anyone else looking.

as a quick fix you can use npm install --legacy-bundling in your project dir. This will make sure that npm disables the optimization and flattening. But remove the node_modules dir before.

Hi,

I have a similar issue. I’m trying to install Serverless locally on Ubuntu 18.04.5 LTS. Node.js: 14.16.0 npm: 7.5.6 Node.js and npm installed as snap

Steps to reproduce

  1. create a folder (mkdir test && cd test)
  2. npm init
  3. npm install serverless (I tried even with sudo npm install -g serverless)

I got this error

npm ERR! code 1
npm ERR! path /home/elia/projects/test/node_modules/serverless
npm ERR! command failed
npm ERR! command sh -c node ./scripts/postinstall.js

No node_modules folder is created during the process.

I even tried to delete npm cache as suggested in a forum post but did not work.

@pmuens Yes, it works with master.

@pmuens I use the get-installed-path node package in some of my code. This let’s you find the installation location of node modules easily. You could use that to retrieve the current location of the tabtab module:

const getInstalledPath = require('get-installed-path');
...
const tabtabPath = getInstalledPath.sync('tabtab', { local: true });

Hey @hash thanks for pointing that out. I just PRed a fix in #3870.

Would be nice if you could try it out. Thanks 👍