diff --git a/packages/angular-cli/blueprints/directive/index.js b/packages/angular-cli/blueprints/directive/index.js index 790c34890acf..ba53e7e95442 100644 --- a/packages/angular-cli/blueprints/directive/index.js +++ b/packages/angular-cli/blueprints/directive/index.js @@ -85,8 +85,10 @@ module.exports = { const returns = []; const className = stringUtils.classify(`${options.entity.name}Directive`); const fileName = stringUtils.dasherize(`${options.entity.name}.directive`); - const componentDir = path.relative(this.dynamicPath.appRoot, this.generatePath); - const importPath = componentDir ? `./${componentDir}/${fileName}` : `./${fileName}`; + const fullGeneratePath = path.join(this.project.root, this.generatePath); + const moduleDir = path.parse(this.pathToModule).dir; + const relativeDir = path.relative(moduleDir, fullGeneratePath); + const importPath = relativeDir ? `./${relativeDir}/${fileName}` : `./${fileName}`; if (!options['skip-import']) { returns.push( diff --git a/packages/angular-cli/blueprints/pipe/index.js b/packages/angular-cli/blueprints/pipe/index.js index d4a65b158641..12f957add718 100644 --- a/packages/angular-cli/blueprints/pipe/index.js +++ b/packages/angular-cli/blueprints/pipe/index.js @@ -73,8 +73,10 @@ module.exports = { const returns = []; const className = stringUtils.classify(`${options.entity.name}Pipe`); const fileName = stringUtils.dasherize(`${options.entity.name}.pipe`); - const componentDir = path.relative(this.dynamicPath.appRoot, this.generatePath); - const importPath = componentDir ? `./${componentDir}/${fileName}` : `./${fileName}`; + const fullGeneratePath = path.join(this.project.root, this.generatePath); + const moduleDir = path.parse(this.pathToModule).dir; + const relativeDir = path.relative(moduleDir, fullGeneratePath); + const importPath = relativeDir ? `./${relativeDir}/${fileName}` : `./${fileName}`; if (!options['skip-import']) { returns.push(