install npm modules in github actions

烂漫一生 提交于 2021-01-29 15:11:18

问题


I have this script that is supposed to create a sitemap on each master deployment

name: create-map
on: push

jobs:
  run_tests:
    runs-on: ubuntu-20.04
    steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-node@v2
      with:
        node-version: '12'
        check-latest: true
    - name: Run script file
      run: |
      
         chmod +x ./scripts/createmap.sh
         ./scripts/createmap.sh
      shell: bash

createmap.sh script looks like

cd public
rm -rf sitemap
mkdir sitemap
cd ..
cd scripts
node ./sitemap-posts.js
node ./compress-map.js
node ./create-one-map.js

curl http://google.com/ping?sitemap=https://website.com/sitemap.xml

The three scripts above eg. sitemap-posts are located in the root folder of my website in scripts folder. They have modules at the top of each file like

const fs = require("fs");
const globby = require("globby");
const prettier = require("prettier");
const firebase = require("firebase");

When a deployment is done an error occurs Error: Cannot find module 'prettier' and Error: Cannot find module 'globby'. I am fairly new to this and i thought these modules would be fetched from my website package.json file.

How do I fix these errors


回答1:


It looks like you didn't run npm install before executing the scripts in createmap.sh.

Please also note that the node_modules directory have to be a sibling of sitemap-posts.js, compress-map.js and create-one-map.js



来源:https://stackoverflow.com/questions/65625629/install-npm-modules-in-github-actions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!