diff --git a/scopes/dev-services/compiler/webpack/ng-webpack-bundler.ts b/scopes/dev-services/compiler/webpack/ng-webpack-bundler.ts index 433bdf43..8bd20592 100644 --- a/scopes/dev-services/compiler/webpack/ng-webpack-bundler.ts +++ b/scopes/dev-services/compiler/webpack/ng-webpack-bundler.ts @@ -117,7 +117,7 @@ export class NgWebpackBundler { entryFiles: target.entries as string[], logger, useNgcc: !!options.ngEnvOptions.useNgcc, - nodeModulesPaths: getNodeModulesPaths(false, isolator, workspace), + nodeModulesPaths: getNodeModulesPaths(true, isolator, workspace), plugins, rootPath: appRootPath, setup: WebpackSetup.Build, diff --git a/scopes/dev-services/preview/preview/preview-app/tsconfig.app.json b/scopes/dev-services/preview/preview/preview-app/tsconfig.app.json index 33430f70..05fbb74a 100644 --- a/scopes/dev-services/preview/preview/preview-app/tsconfig.app.json +++ b/scopes/dev-services/preview/preview/preview-app/tsconfig.app.json @@ -23,8 +23,7 @@ "es2018", "dom", "esnext.asynciterable" - ], - "types": ["node"] + ] }, "angularCompilerOptions": { "enableI18nLegacyMessageIdFormat": false, diff --git a/scopes/versions/common/angular-common/utils.ts b/scopes/versions/common/angular-common/utils.ts index 8d79c19e..29596f7a 100644 --- a/scopes/versions/common/angular-common/utils.ts +++ b/scopes/versions/common/angular-common/utils.ts @@ -1,6 +1,6 @@ -import { ComponentID } from "@teambit/component"; -import { EnvContext } from "@teambit/envs"; -import { IsolatorMain } from "@teambit/isolator"; +import { ComponentID } from '@teambit/component'; +import { EnvContext } from '@teambit/envs'; +import { IsolatorMain } from '@teambit/isolator'; import { Workspace, WorkspaceAspect } from '@teambit/workspace'; import { resolve } from 'path'; @@ -18,31 +18,33 @@ export function getWorkspace(context: EnvContext): Workspace | undefined { } export function getNodeModulesPaths(build: boolean, isolator: IsolatorMain, workspace?: Workspace): string[] { - if (!workspace) { - return []; - } - const workspaceDir = workspace.path; - const scopeAspectsRootDir = isolator.getCapsulesRootDir(workspace.scope.getAspectCapsulePath()); - const workspaceCapsulesRootDir = build ? isolator.getCapsulesRootDir(workspace.path) : undefined; - const nodeModulesPaths: string[] = []; - const workspaceNodeModules = resolve(workspaceDir, 'node_modules'); - if (workspaceCapsulesRootDir) { - const workspaceCapsuleNodeModules = resolve(workspaceCapsulesRootDir, 'node_modules'); - // Add the workspace capsule node modules - nodeModulesPaths.push(workspaceCapsuleNodeModules); - } + if (workspace) { + const workspaceDir = workspace.path; + const scopeAspectsRootDir = isolator.getCapsulesRootDir({ baseDir: workspace.scope.getAspectCapsulePath() }); + const workspaceCapsulesRootDir = build ? isolator.getCapsulesRootDir({ baseDir: workspace.path }) : undefined; + + const workspaceNodeModules = resolve(workspaceDir, 'node_modules'); + + if (workspaceCapsulesRootDir) { + const workspaceCapsuleNodeModules = resolve(workspaceCapsulesRootDir, 'node_modules'); + // Add the workspace capsule node modules + nodeModulesPaths.push(workspaceCapsuleNodeModules); + } + + // Check if we are in the aspects' capsule + if (!__dirname.startsWith(workspaceNodeModules)) { + const aspectsCapsuleNodeModules = resolve(scopeAspectsRootDir, 'node_modules'); + // Add the aspects capsule node modules + nodeModulesPaths.push(aspectsCapsuleNodeModules); + } - // Check if we are in the aspects capsule - if (!__dirname.startsWith(workspaceNodeModules)) { - const aspectsCapsuleNodeModules = resolve(scopeAspectsRootDir, 'node_modules'); - // Add the aspects capsule node modules - nodeModulesPaths.push(aspectsCapsuleNodeModules); + // Add the workspace node modules + nodeModulesPaths.push(workspaceNodeModules, 'node_modules'); } - // Add the workspace node modules - nodeModulesPaths.push(workspaceNodeModules, 'node_modules'); + nodeModulesPaths.push('node_modules'); return nodeModulesPaths; } @@ -57,7 +59,7 @@ export function optionValue(value: T | undefined, defaultValue: T) { export async function loadEsmModule(modulePath: string): Promise { try { return await import(modulePath); - } catch(e) { + } catch (e) { return new Function('modulePath', `return import(modulePath)`)(modulePath) as Promise; } }