0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AWS SAM CLI package-lock.jsonが無視される問題を解決する

0
Last updated at Posted at 2021-02-06

問題

ビルドするとビルドフォルダにpackage-lock.jsonがいない。
そこでnpm installしているため、ビルドしたらバージョンが変わる可能性があるのでなんとかしたい。

解決

npm shrinkwrapnpm-shrinkwrap.jsonを作る。

参考:
https://www.gitmemory.com/issue/aws/aws-lambda-builders/221/763109320

検証

一回古いバージョン固定でインストール、その後package.json書き換えてビルド、ビルド先のバージョンを調べる。

package-lock.jsonの場合

package.json
古いバージョン指定

  "dependencies": {
    "date-fns": "2.16.0",
  }

インストール
$ npm intall

package-lock.json

  "dependencies": {
    "date-fns": {
      "version": "2.16.0",

package.json
メジャーバージョン一致してればOK設定に変える

  "dependencies": {
    "date-fns": "^2.16.0",

※npm installしてもpackage-lock.jsonは変わらない。

ビルド実行
$ sam build

buildフォルダ下のnode_modules/date-fns/package.json
最新になってしまった。

  "_from": "date-fns@^2.16.0",
  "_id": "date-fns@2.17.0",

shrinkwrapの場合

$ npm shrinkwrap
npm notice package-lock.json has been renamed to npm-shrinkwrap.json. npm-shrinkwrap.json will be used for future installations.

package-lock.jsonをnpm-shrinkwrap.jsonにリネームしたよとのこと。

npm-shrinkwrap.json

  "dependencies": {
    "date-fns": {
      "version": "2.16.0",

ビルド

$ sam build

buildフォルダ下のnode_modules/date-fns/package.json
古いバージョンに固定されている。

  "_from": "date-fns@2.16.0",
  "_id": "date-fns@2.16.0",

ビルドフォルダ下にnpm-shrinkwrap.jsonがちゃんとあった。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?