diff --git a/code/core/src/common/js-package-manager/NPMProxy.test.ts b/code/core/src/common/js-package-manager/NPMProxy.test.ts index 4a783017d917..11f34a986bf1 100644 --- a/code/core/src/common/js-package-manager/NPMProxy.test.ts +++ b/code/core/src/common/js-package-manager/NPMProxy.test.ts @@ -428,7 +428,7 @@ describe('NPM Proxy', () => { describe('parseErrors', () => { it('should parse npm errors', () => { - const NPM_RESOLVE_ERROR_SAMPLE = ` + const NPM_LEGACY_RESOLVE_ERROR_SAMPLE = ` npm ERR! npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree @@ -439,6 +439,17 @@ describe('NPM Proxy', () => { npm ERR! react@"30" from the root project `; + const NPM_RESOLVE_ERROR_SAMPLE = ` + npm error + npm error code ERESOLVE + npm error ERESOLVE unable to resolve dependency tree + npm error + npm error While resolving: before-storybook@1.0.0 + npm error Found: react@undefined + npm error node_modules/react + npm error react@"30" from the root project + `; + const NPM_TIMEOUT_ERROR_SAMPLE = ` npm notice npm notice New major version of npm available! 8.5.0 -> 9.6.7 @@ -451,6 +462,9 @@ describe('NPM Proxy', () => { npm ERR! network This is a problem related to network connectivity. `; + expect(npmProxy.parseErrorFromLogs(NPM_LEGACY_RESOLVE_ERROR_SAMPLE)).toEqual( + 'NPM error ERESOLVE - Dependency resolution error.' + ); expect(npmProxy.parseErrorFromLogs(NPM_RESOLVE_ERROR_SAMPLE)).toEqual( 'NPM error ERESOLVE - Dependency resolution error.' ); diff --git a/code/core/src/common/js-package-manager/NPMProxy.ts b/code/core/src/common/js-package-manager/NPMProxy.ts index 90378de122cf..ea673f9df301 100644 --- a/code/core/src/common/js-package-manager/NPMProxy.ts +++ b/code/core/src/common/js-package-manager/NPMProxy.ts @@ -28,8 +28,8 @@ type NpmDependencies = { export type NpmListOutput = { dependencies: NpmDependencies; }; +const NPM_ERROR_REGEX = /npm (ERR!|error) (code|errno) (\w+)/i; -const NPM_ERROR_REGEX = /npm ERR! code (\w+)/; const NPM_ERROR_CODES = { E401: 'Authentication failed or is required.', E403: 'Access to the resource is forbidden.', @@ -320,7 +320,7 @@ export class NPMProxy extends JsPackageManager { const match = logs.match(NPM_ERROR_REGEX); if (match) { - const errorCode = match[1] as keyof typeof NPM_ERROR_CODES; + const errorCode = match[3] as keyof typeof NPM_ERROR_CODES; if (errorCode) { finalMessage = `${finalMessage} ${errorCode}`; }