Skip to content

[bug] can't read package.json in postinstall.jsΒ #112

@tjx666

Description

@tjx666

error message:

 error /layers/google.nodejs.yarn/yarn_modules/node_modules/simple-git-hooks: Command failed.
Step #2 - "build": Exit code: 1
Step #2 - "build": Command: node ./postinstall.js
Step #2 - "build": Arguments: 
Step #2 - "build": Directory: /layers/google.nodejs.yarn/yarn_modules/node_modules/simple-git-hooks
Step #2 - "build": Output:
Step #2 - "build": node:internal/fs/utils:356
Step #2 - "build":     throw err;
Step #2 - "build":     ^
Step #2 - "build": 
Step #2 - "build": Error: ENOENT: no such file or directory, stat '/layers/google.nodejs.yarn/yarn_modules/package.json'
Step #2 - "build":     at Object.statSync (node:fs:1688:3)
Step #2 - "build":     at _getPackageJson (/layers/google.nodejs.yarn/yarn_modules/node_modules/simple-git-hooks/simple-git-hooks.js:139:13)
Step #2 - "build":     at checkSimpleGitHooksInDependencies (/layers/google.nodejs.yarn/yarn_modules/node_modules/simple-git-hooks/simple-git-hooks.js:80:9)
Step #2 - "build":     at postinstall (/layers/google.nodejs.yarn/yarn_modules/node_modules/simple-git-hooks/postinstall.js:11:9)
Step #2 - "build":     at Object.<anonymous> (/layers/google.nodejs.yarn/yarn_modules/node_modules/simple-git-hooks/postinstall.js:19:1)
Step #2 - "build":     at Module._compile (node:internal/modules/cjs/loader:1364:14)
Step #2 - "build":     at Module._extensions..js (node:internal/modules/cjs/loader:1422:10)
Step #2 - "build":     at Module.load (node:internal/modules/cjs/loader:1203:32)
Step #2 - "build":     at Module._load (node:internal/modules/cjs/loader:1019:12)
Step #2 - "build":     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:128:12) {
Step #2 - "build":   errno: -2,
Step #2 - "build":   syscall: 'stat',
Step #2 - "build":   code: 'ENOENT',
Step #2 - "build":   path: '/layers/google.nodejs.yarn/yarn_modules/package.json'
Step #2 - "build": }
Step #2 - "build": 

expect:

don't do anything when package.json not exists in project

What's more

I think the postinstall.js should just skip when find self install in CI environment. You can use https://www.npmjs.com/package/ci-info

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions