yarn 으로 package 를 설치하는데 에러가 발생했다

 

에러 전문

Progress: resolved 763, reused 737, downloaded 0, added 739, done
node_modules/.pnpm/node-sass@9.0.0/node_modules/node-sass: Running install script, done in 260ms
node_modules/.pnpm/node-sass@9.0.0/node_modules/node-sass: Running postinstall script, failed in 366ms
.../node_modules/node-sass postinstall$ node scripts/build.js
│ Binary found at /Users/mik_a/Desktop/dev/ezerp/node_modules/.pnpm/node-sass@9.0.0/node_modules/node-sass/vendor/darwin-arm64-108/binding.node
│ Testing binary
│ Binary has a problem: Error: dlopen(/Users/mik_a/Desktop/dev/ezerp/node_modules/.pnpm/node-sass@9.0.0/node_modules/node-sass/vendor/darwin-arm64-108/binding.node, 0x0001): tried: '/Users/mik_a/Desktop/dev/ezerp/node_modules/.pnpm/node-sa…
│     at Module._extensions..node (node:internal/modules/cjs/loader:1338:18)
│     at Module.load (node:internal/modules/cjs/loader:1117:32)
│     at Module._load (node:internal/modules/cjs/loader:958:12)
│     at Module.require (node:internal/modules/cjs/loader:1141:19)
│     at require (node:internal/modules/cjs/helpers:110:18)
│     at module.exports (/Users/mik_a/Desktop/dev/ezerp/node_modules/.pnpm/node-sass@9.0.0/node_modules/node-sass/lib/binding.js:19:10)
│     at Object.<anonymous> (/Users/mik_a/Desktop/dev/ezerp/node_modules/.pnpm/node-sass@9.0.0/node_modules/node-sass/lib/index.js:13:35)
│     at Module._compile (node:internal/modules/cjs/loader:1254:14)
│     at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
│     at Module.load (node:internal/modules/cjs/loader:1117:32) {
│   code: 'ERR_DLOPEN_FAILED'
│ }
│ Building the binary locally
│ Building: /usr/local/bin/node /Users/mik_a/Desktop/dev/ezerp/node_modules/.pnpm/node-gyp@8.4.1/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
│ gyp info it worked if it ends with ok
│ gyp verb cli [
│ gyp verb cli   '/usr/local/bin/node',
│ gyp verb cli   '/Users/mik_a/Desktop/dev/ezerp/node_modules/.pnpm/node-gyp@8.4.1/node_modules/node-gyp/bin/node-gyp.js',
│ gyp verb cli   'rebuild',
│ gyp verb cli   '--verbose',
│ gyp verb cli   '--libsass_ext=',
│ gyp verb cli   '--libsass_cflags=',
│ gyp verb cli   '--libsass_ldflags=',
│ gyp verb cli   '--libsass_library='
│ gyp verb cli ]
│ gyp info using node-gyp@8.4.1
│ gyp info using node@18.16.0 | darwin | arm64
│ gyp verb command rebuild []
│ gyp verb command clean []
│ gyp verb clean removing "build" directory
│ gyp verb command configure []
│ gyp verb find Python Python is not set from command line or npm configuration
│ gyp verb find Python Python is not set from environment variable PYTHON
│ gyp verb find Python checking if "python3" can be used
│ gyp verb find Python - executing "python3" to get executable path
│ gyp verb find Python - executable path is "/Library/Frameworks/Python.framework/Versions/3.12/bin/python3"
│ gyp verb find Python - executing "/Library/Frameworks/Python.framework/Versions/3.12/bin/python3" to get version
│ gyp verb find Python - version is "3.12.2"
│ gyp info find Python using Python version 3.12.2 found at "/Library/Frameworks/Python.framework/Versions/3.12/bin/python3"
│ gyp verb get node dir no --target version specified, falling back to host node version: 18.16.0
│ gyp verb command install [ '18.16.0' ]
│ gyp verb install input version string "18.16.0"
│ gyp verb install installing version: 18.16.0
│ gyp verb install --ensure was passed, so won't reinstall if already installed
│ gyp verb install version is already installed, need to check "installVersion"
│ gyp verb got "installVersion" 11
│ gyp verb needs "installVersion" 9
│ gyp verb install version is good
│ gyp verb get node dir target node version installed: 18.16.0
│ gyp verb build dir attempting to create "build" dir: /Users/mik_a/Desktop/dev/ezerp/node_modules/.pnpm/node-sass@9.0.0/node_modules/node-sass/build
│ gyp verb build dir "build" dir needed to be created? Yes
│ gyp verb build/config.gypi creating config file
│ gyp verb build/config.gypi writing out config file: /Users/mik_a/Desktop/dev/ezerp/node_modules/.pnpm/node-sass@9.0.0/node_modules/node-sass/build/config.gypi
│ gyp verb config.gypi checking for gypi file: /Users/mik_a/Desktop/dev/ezerp/node_modules/.pnpm/node-sass@9.0.0/node_modules/node-sass/config.gypi
│ gyp verb common.gypi checking for gypi file: /Users/mik_a/Desktop/dev/ezerp/node_modules/.pnpm/node-sass@9.0.0/node_modules/node-sass/common.gypi
│ gyp verb gyp gyp format was not specified; forcing "make"
│ gyp info spawn /Library/Frameworks/Python.framework/Versions/3.12/bin/python3
│ gyp info spawn args [
│ gyp info spawn args   '/Users/mik_a/Desktop/dev/ezerp/node_modules/.pnpm/node-gyp@8.4.1/node_modules/node-gyp/gyp/gyp_main.py',
│ gyp info spawn args   'binding.gyp',
│ gyp info spawn args   '-f',
│ gyp info spawn args   'make',
│ gyp info spawn args   '-I',
│ gyp info spawn args   '/Users/mik_a/Desktop/dev/ezerp/node_modules/.pnpm/node-sass@9.0.0/node_modules/node-sass/build/config.gypi',
│ gyp info spawn args   '-I',
│ gyp info spawn args   '/Users/mik_a/Desktop/dev/ezerp/node_modules/.pnpm/node-gyp@8.4.1/node_modules/node-gyp/addon.gypi',
│ gyp info spawn args   '-I',
│ gyp info spawn args   '/Users/mik_a/Library/Caches/node-gyp/18.16.0/include/node/common.gypi',
│ gyp info spawn args   '-Dlibrary=shared_library',
│ gyp info spawn args   '-Dvisibility=default',
│ gyp info spawn args   '-Dnode_root_dir=/Users/mik_a/Library/Caches/node-gyp/18.16.0',
│ gyp info spawn args   '-Dnode_gyp_dir=/Users/mik_a/Desktop/dev/ezerp/node_modules/.pnpm/node-gyp@8.4.1/node_modules/node-gyp',
│ gyp info spawn args   '-Dnode_lib_file=/Users/mik_a/Library/Caches/node-gyp/18.16.0/<(target_arch)/node.lib',
│ gyp info spawn args   '-Dmodule_root_dir=/Users/mik_a/Desktop/dev/ezerp/node_modules/.pnpm/node-sass@9.0.0/node_modules/node-sass',
│ gyp info spawn args   '-Dnode_engine=v8',
│ gyp info spawn args   '--depth=.',
│ gyp info spawn args   '--no-parallel',
│ gyp info spawn args   '--generator-output',
│ gyp info spawn args   'build',
│ gyp info spawn args   '-Goutput_dir=.'
│ gyp info spawn args ]
│ Traceback (most recent call last):
│   File "/Users/mik_a/Desktop/dev/ezerp/node_modules/.pnpm/node-gyp@8.4.1/node_modules/node-gyp/gyp/gyp_main.py", line 42, in <module>
│     import gyp  # noqa: E402
│     ^^^^^^^^^^
│   File "/Users/mik_a/Desktop/dev/ezerp/node_modules/.pnpm/node-gyp@8.4.1/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 9, in <module>
│     import gyp.input
│   File "/Users/mik_a/Desktop/dev/ezerp/node_modules/.pnpm/node-gyp@8.4.1/node_modules/node-gyp/gyp/pylib/gyp/input.py", line 19, in <module>
│     from distutils.version import StrictVersion
│ ModuleNotFoundError: No module named 'distutils'
│ gyp ERR! configure error 
│ gyp ERR! stack Error: `gyp` failed with exit code: 1
│ gyp ERR! stack     at ChildProcess.onCpExit (/Users/mik_a/Desktop/dev/ezerp/node_modules/.pnpm/node-gyp@8.4.1/node_modules/node-gyp/lib/configure.js:259:16)
│ gyp ERR! stack     at ChildProcess.emit (node:events:513:28)
│ gyp ERR! stack     at ChildProcess._handle.onexit (node:internal/child_process:291:12)
│ gyp ERR! System Darwin 22.4.0
│ gyp ERR! command "/usr/local/bin/node" "/Users/mik_a/Desktop/dev/ezerp/node_modules/.pnpm/node-gyp@8.4.1/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_li…
│ gyp ERR! cwd /Users/mik_a/Desktop/dev/ezerp/node_modules/.pnpm/node-sass@9.0.0/node_modules/node-sass
│ gyp ERR! node -v v18.16.0
│ gyp ERR! node-gyp -v v8.4.1
│ gyp ERR! not ok 
│ Build failed with error code: 1
└─ Failed in 366ms at /Users/mik_a/Desktop/dev/ezerp/node_modules/.pnpm/node-sass@9.0.0/node_modules/node-sass
 ELIFECYCLE  Command failed with exit code 1.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

 

 

node-gyp 에서 python 으로 뭔가를 하는가보다.

거기서 distutils 라는 모듈이 없다고 떴다.

 

검색해보니 setuptools 패키지를 업그레이드 하라고 해서 해줬다.

python3 -m pip install --upgrade setuptools

 

 

이후엔 설치가 잘 됐다.

npm i -g npm-check-updates
ncu -u
npm install

 

알아서 최신 버전으로 업데이트 된다

node.js 를 사용한 서버에서 new Date() 로 현재시간을 저장하는 코드가 있었다.

근데 서버를 하나 빌렸더니 외국 어딘가로 돼있어서 시간 저장이 이상하게 되더라...

서버 시간을 바꾸는 법도 있겠지만 가끔 docker 사용시 서버 시간이 외국으로 돼있는 경우도 있기에

그냥 nodejs 에서 처리하기로 생각

 

예전엔 moment.js 를 썼었는데 요새 크기가 너무 커지고 뭐 별로라해서 day.js 사용해봤다.

 

npm install dayjs

 

// node.js

const dayjs = require('dayjs');
const timezone = require('dayjs/plugin/timezone')
const utc = require('dayjs/plugin/utc');

dayjs.extend(utc)
dayjs.extend(timezone)

console.log(dayjs().tz("Asia/Seoul"))
console.log(new Date().toString());

 

root@002b13b84c41:/test# node t.js

// console.log(dayjs().tz("Asia/Seoul"))
d {
  '$L': 'en',
  '$d': 2021-04-13T18:03:55.594Z,
  '$x': { '$timezone': 'Asia/Seoul' },
  '$y': 2021,
  '$M': 3,
  '$D': 13,
  '$W': 2,
  '$H': 9,
  '$m': 3,
  '$s': 55,
  '$ms': 594,
  '$offset': 540,
  '$u': false }
  
// console.log(new Date().toString())
Mon Apr 12 2021 15:03:55 GMT-0900 (Hawaii-Aleutian Daylight Time)

 

하와이-알류샨 시간대에서 현재 한국 시간인 9시 3분을 구할 수 있다

npm 에 패키지를 올릴려고

npm publish 를 했는데

 

npm ERR! code E403

npm ERR! 403 403 Forbidden - Put [패키지 주소] - Forbidden

npm ERR! 403 In most cases, you or one of your dependencies are requesting

npm ERR! 403 a package version that is forbidden by your security policy.

 

이런 에러가 뜨더라...

 

npm 회원가입할 때 이메일 인증을 안해서 뜨는거였다. 이메일 인증하고 해결.. ㅎㅎ;;;

회사 메신저로 Mattermost(매터모스트)를 사용 중이다.

얼마 전 사원들 생일파티(...) 담당을 맡게되었는데 메신저에 생일파티 알람을 주면 어떨까 싶어서 찾아봤다.

 

github.com/jonathanwiesel/node-mattermost

 

jonathanwiesel/node-mattermost

a nodejs module for sending and receiving messages from Mattermost - jonathanwiesel/node-mattermost

github.com

위의 프로젝트를 이용했다.

일단 테스트를 위해 채널을 하나 새로 만들었다.

 

1. Hook URL 구하기

 

test channel 생성

 

Menu -> intergrations

작성 후 제일 아래에 Save 를 눌러준다.

3번째의 Channel 은 메세지 수신을 위해 사용하는 듯 한데.. 나중에 더 자세히 찾아봐야겠다.

 

 

해당 URL 이 hook url 이다. 다시 들어와서 보는것도 가능하니 막 어디 적어둘 필요는 없을 듯 하다.

 

 

2. NodeJS js 파일 작성하기

일단 npm 으로 상단의 git 프로젝트를 인스톨하자

npm install node-mattermost

 

//app.js
const Mattermost = require('node-mattermost');
const hookurl = json.hookurl; // 상단에서 구한 hook url
const mattermost = new Mattermost(hookurl);

// 프사 설정을 위해
function base64_encode(file) {
    var bitmap = fs.readFileSync(file);
    return bitmap.toString('base64');
}

mattermost.send({
  text: "생일 축하합니다",

  // 채널명을 입력해준다. 채널명이 한글이면 좀 다른데 아래에서 설명..
  channel: '#test',
  username: '생일축하 봇',
  // 프로필 사진을 지정해준다. 나는 같은 폴더에 있는 케이크 사진을 base64 형태로 추가했다 
  icon_url: 'data:image/png;base64,' + base64_encode('./public/img/cake.png'),

})

 

실행해보자

node app.js

테스트

 

 

3. 채널명이 한글일 때

 

{
    // ...
    channel : 'testz'
    // ...
}

 

+ Recent posts