Windows에서 깊은 node_modules 구조로 Node.js 애플리케이션을 배포하는 방법은 무엇입니까?
궁금한 문제가 발생했습니다. 일부 Node.js 모듈에는 폴더 계층 구조 가 너무 깊어 Windows 복사 명령 (또는 Copy-Item
실제로 사용하는 PowerShell )이 경로가 250 이상일 때 악명 높은 "경로가 너무 깁니다"오류가 발생합니다. 긴 문자.
예를 들어 다음은 단일 노드 모듈이 만들 수있는 폴더 계층입니다.
node_modules\nodemailer\node_modules\simplesmtp\node_modules\
xoauth2\node_modules\request\node_modules\form-data\node_modules\
combined-stream\node_modules\delayed-stream\...
미친 것처럼 보이지만 Node 모듈에서는 현실입니다.
배포하는 동안 복사-붙여 넣기를 사용해야합니다 (Git 배포가 옵션 인 Heroku와 같은 "영리한"대상 플랫폼을 사용하지 않음). 이것은 Windows에서 심각한 제한 사항입니다.
npm 명령이나 node_modules
폴더를 압축 하거나 런타임에 실제로 필요한 것만 포함하는 것이 있습니까? (노드 모듈은 일반적으로 test
배포 할 필요가없는 폴더 등을 포함합니다 .)이 문제를 해결하는 다른 아이디어가 있습니까? Windows를 사용하지 않는 것은 불행히도 옵션이 아닙니다. :)
npm v3 (최근 출시)는 종속성을 평탄화하여이 문제를 해결합니다 . 섹션 아래 https://github.com/npm/npm/releases/tag/v3.0.0 의 릴리스 노트를 확인 flat flat
하십시오.
그리고이 문제에 대한 마지막 댓글 https://github.com/npm/npm/issues/3697
이것에 추가하기 위해 ... 나를 도운 또 다른 것은 설치된 모든 모듈을 npm ls
.
모듈과 버전의 트리를 제공 할 것입니다 ... 거기에서 어떤 것이 중복인지 식별하기가 매우 쉽습니다 ... npm dedupe
나를 위해 아무것도하지 않았습니다. 그것이 버그인지 또는 무엇인지 잘 모르겠습니다 (노드 v 10.16).
따라서 중복 모듈을 식별 한 후에는를 사용하여 루트 node_module 디렉토리에 설치합니다 npm install dupemodule@1.2.3 --save-dev
. 버전이 중요합니다.
그 후 node_modules 디렉토리를 지우고 새로운 npm install
.
짧은 버전
npm ls
설치된 모든 모듈 목록을 가져옵니다.- 해당 모듈을 살펴보고 중복 모듈을 식별합니다 ( 버전이 중요 함 ).
npm install module@version --save-dev
루트 node_modules 디렉토리에 해당 모듈을 설치하고 package.json을 업데이트하십시오.rmdir node_modules
node_modules 디렉토리를 삭제합니다.npm install
종속성의 새 복사본을 가져옵니다.
일단 그렇게하면 모든 것이 훨씬 깨끗해졌습니다.
또한 package.json 파일에 주석을 달아 node_modules 트리를 평평하게하기 위해 가져온 파일을 표시하는 것이 좋습니다.
나는 당신의 제약을 감안할 때 훌륭한 해결책이 없다고 생각하지만 여기에 도움이 될만한 몇 가지가 있습니다.
npm dedupe
일부 경로를 단축 할 수있는 디렉토리 계층을 최적화 하는 데 사용 하십시오.- 사용
npm install --production
개발 도구없이 설치 - 깊이 중첩 된 종속성 중 일부를 가져 와서 (문제를 피할 수있을 정도로만 권장합니다) 최상위 node_modules 디렉토리로 이동합니다. 이들을 추적하여 어떤 것이 진정한 종속성인지 그리고이 문제에 대한 해결 방법인지 알 수 있습니다.
- 또는 이러한 깊은 종속성 중 일부를 가장 높은
node_modules
디렉터리 로 이동your_project/node_modules/pkg_with_deep_deps
하면 경로가 충분히 짧지 만 여전히 작동 할 수 있습니다. 그래서 이것은your_project/node_modules/pkg_with_deep_deps/node_modules
.require
런타임에 제대로 찾을 수 있어야 한다고 생각 합니다. 수동으로 변경 한 내용과 변경 한 이유를 명확하게 문서화하고 자신의 실제 종속성을 정확하게 표현하면됩니다.package.json
이 문제에 대해 자세히 설명 하는 github 문제 토론 이 있습니다.
여기에 종속성을 평평하게하는 "npm-flatten"이라는 노드 모듈을 작성했습니다. https://www.npmjs.org/package/npm-flatten
배포를 찾고 있다면 여기에 완전한 node.js 환경을 .NET 프로젝트와 통합하는 NuGet 패키지를 작성했습니다. http://www.nuget.org/packages/NodeEnv/
피드백을 환영합니다.
저에게 도움이 된 것은 로컬 드라이브를 Node.js 폴더에 매핑하는 것입니다.
net use n : \ computername \ c $ \ users \ myname \ documents \ node.js / persistent : yes
이전 : c : \ users \ myname \ documents \ node.js \ projectname (45 자) 이후 : n : \ projectname (14 자, 31 자 이하)
많은 경우 이로 인해 일부 모듈을 설치할 수있었습니다.
오늘 모든 코드를 USB 드라이브에 백업하려고 할 때이 문제를 다시 발견했다고 말할 것입니다.
"C:\Users\myname\Documents\Node.js\angular-phonecat\node_modules\karma\node_modules\chokidar\node_modules\anymatch\node_modules\micromatch\node_modules\regex-cache\node_modules\benchmarked\node_modules\file-reader\node_modules\extend-shallow\benchmark\fixtures is too long."
Even when I tried to back them up using the N: drive letter it still failed in some cases due to path lengths but it was just enough to fix the one above.
1) During release build, You can prevent Visual studio scanning these files / folder by setting the folder properties as a Hidden folder (JUST set it to node_modules). Reference: http://issues.umbraco.org/issue/U4-6219#comment=67-19103
2) You can exclude files or folder that are published during packaging by including following XML node in the CsProject file.
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
...
<OutputPath>bin\</OutputPath>
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
<ExcludeFilesFromDeployment>File1.aspx;File2.aspx</ExcludeFilesFromDeployment>
<ExcludeFoldersFromDeployment>Folder1;Folder2</ExcludeFoldersFromDeployment>
</PropertyGroup>
I found one solution from Microsoft Node.js Guidelines.
- Start in a short path (e.g. c:\src)
> npm install -g rimraf
delete files that exceedmax_path
> npm dedupe
moves duplicate packages to top-level> npm install -g flatten-packages
moves all packages to top-level, but can cause versioning issues- Upgrade to
npm@3
which attempts to the make thenode_modules
folder heirarchy maximally flat.- Ships with Node v5
- Or…
> npm install –g npm-windows-upgrade
This is a not a proper solution, rather a work around when you are in a hurry, but you can use 7-Zip to zip your folder, move the zipped file and unzip it without any issue.
We used that solution to deploy a Node.js application where it was not possible to do a clean npm install.
'IT story' 카테고리의 다른 글
MySQL-모든 필드를 색인화하지 않는 이유는 무엇입니까? (0) | 2020.09.03 |
---|---|
Html.Textbox VS Html.TextboxFor (0) | 2020.09.03 |
배치 파일 : 파일을 읽는 방법? (0) | 2020.09.03 |
페이지의 메모리 사용량을 찾는 jQuery 또는 javascript (0) | 2020.09.03 |
바이너리 트리를 구현하는 방법? (0) | 2020.09.03 |