Cannot find module '@angular-cli/base-href-webpack'
Hello,
I have a problem since installing the latest version (1.0.0-beta.11-webpack.8). When i run any ng command in a Terminal, this error appears : Cannot find module '@angular-cli/base-href-webpack' Error: Cannot find module '@angular-cli/base-href-webpack' at Function.Module._resolveFilename (module.js:455:15) at Function.Module._load (module.js:403:25) at Module.require (module.js:483:17) at require (internal/module.js:20:19) .... And When i try : 'npm install @angular-cli/base-href-webpack', it tells that this module is not found. Is this module missing or there's a trick to install it directly from the angular-cli source ? I give more details below and complete stack trace in attached file. Thanks.
- OS? Windows 7, 8 or 10. Linux (which distribution). Mac OSX (Yosemite? El Capitan?) Linux, XUbuntu 15.10
- Versions. Please run
ng --version. If there's nothing outputted, please run in a Terminal:node --versionand paste the result here: ng --version failed but the source code is 1.0.0-beta.11-webpack.8 node --version --> v6.5.0 npm --version --> 3.10.3 - Repro steps. Was this an app that wasn't created using the CLI? What change did you do on your code? etc. I only clone with git the angular-cli repo and installed it with npm.
- The log given by the failure. Normally this include a stack trace and some more information.
See complete stack trace in attached error.log.txt file. --> error.log.txt
- Mention any other details that might be useful.
i have same problem bro...
I think that base-href-webpack plugin is not properly published. When angular-cli is installed and linked (with npm -link ), it works. This behaviour matches source code below. In lib/bootstrap-local.js there's a test that mocks the module loader when npm linked:
// If we're running locally, meaning npm linked. This is basically "developer mode".
if (!__dirname.match(/\/node_modules\//)) {
const packages = require('./packages');
// We mock the module loader so that we can fake our packages when running locally.
const Module = require('module');
const oldLoad = Module._load;
Module._load = function (request, parent) {
if (request in packages) {
return oldLoad.call(this, packages[request].main, parent);
} else {
return oldLoad.apply(this, arguments);
}
};
}
When module loader is mocked, it works (you can try to comment the if), but it should not be the right solution :)
Same Issue and if you try to compile the base-href-webpack from the package folder of the source this ts error shows up:
packages/base-href-webpack/src/base-href-webpack-plugin.spec.ts(22,27): error TS2345: Argument of type 'TemplateStringsArray' is not assignable to parameter of type 'string[]'.
Property 'push' is missing in type 'TemplateStringsArray'.
packages/base-href-webpack/src/base-href-webpack-plugin.spec.ts(41,56): error TS2345: Argument of type 'TemplateStringsArray' is not assignable to parameter of type 'string[]'.
packages/base-href-webpack/src/base-href-webpack-plugin.spec.ts(55,46): error TS2345: Argument of type 'TemplateStringsArray' is not assignable to parameter of type 'string[]'.
packages/base-href-webpack/src/base-href-webpack-plugin.spec.ts(59,54): error TS2345: Argument of type 'TemplateStringsArray' is not assignable to parameter of type 'string[]'.
I was able to get it working by compiling it by enclosing the arguments of the onelinetrim areas in ([]) for the base-href-webpack-plugin.spec.ts file:
import {oneLineTrim} from 'common-tags';
import {BaseHrefWebpackPlugin} from './base-href-webpack-plugin';
function mockCompiler(indexHtml: string, callback: Function) {
return {
plugin: function (event: any, compilerCallback: Function) {
const compilation = {
plugin: function (hook: any, compilationCallback: Function) {
const htmlPluginData = {
html: indexHtml
};
compilationCallback(htmlPluginData, callback);
}
};
compilerCallback(compilation);
}
};
}
describe('base href webpack plugin', () => {
const html = oneLineTrim([`
<html>
<head></head>
<body></body>
</html>
`]);
it('should do nothing when baseHref is null', () => {
const plugin = new BaseHrefWebpackPlugin({ baseHref: null });
const compiler = mockCompiler(html, (x: any, htmlPluginData: any) => {
expect(htmlPluginData.html).toEqual('<body><head></head></body>');
});
plugin.apply(compiler);
});
it('should insert base tag when not exist', function () {
const plugin = new BaseHrefWebpackPlugin({ baseHref: '/' });
const compiler = mockCompiler(html, (x: any, htmlPluginData: any) => {
expect(htmlPluginData.html).toEqual(oneLineTrim([`
<html>
<head><base href="/"></head>
<body></body>
</html>
`]));
});
plugin.apply(compiler);
});
it('should replace href attribute when base tag already exists', function () {
const plugin = new BaseHrefWebpackPlugin({ baseHref: '/myUrl/' });
const compiler = mockCompiler(oneLineTrim([`
<head><base href="/" target="_blank"></head>
<body></body>
`]), (x: any, htmlPluginData: any) => {
expect(htmlPluginData.html).toEqual(oneLineTrim([`
<head><base href="/myUrl/" target="_blank"></head>
<body></body>
`]));
});
plugin.apply(compiler);
});
});
and then run tsc -P packages/base-href-webpack on the root directory of the angular-cli source.
Make a folder in node_modules/@angular-cli called base-href-webpack and paste the compiled code into the folder and the error disappears when you run ng commands
#2058
PLEASE FIX THIS. It has been 10 days since opening this issue, and there is no solution. If anybody has a workaround, PLEASE SHARE. @astar55 Is there any way without messing with Angular-CLI source myself, to overcome this error?..
@tx8821 it seems in the latest commit, you can run tsc on the base-href-webpack in the package folder without having to mess with the source. But you still need to move the compiled files to @angular-cli in node_modules
Ok, i will try this. Thanks.
still broken in 1.0.0-beta.11-webpack.9
Yeah it is broken in 1.0.0-beta.11-webpack.9 - First time I encountered this problem too. Strangeness...
As a workaround, I added "@angular-cli/base-href-webpack": "^1.0.0" to my project's devDependencies section and it seems to work. Does this work for anyone else? I believe that one issue 2090 is fixed, I can remove it.
@billdwhite I just tried that and now I get Error: Cannot find module 'typescript' crazy days...
@jwuliger sorry, i forgot to mention I have typescript locked at 2.0.0 in my package.json.
@billdwhite I was able to get it working with a patch the CLI team made to master with npm-link. Thanks for the info!
I am still getting this error with [email protected]
I got the same error with [email protected]. So it fixed with npm install @angular-cli/base-href-webpack
Fixed in beta.14+
I'm using version beta.15, and still facing the same issue... :-(.
Done several npm uninstall -g angular-cli , followed by npm cache clean, and npm install -g angular-cli, but it has not helped...
Node Version: 6.6.0 Npm Version: 3.10.8
i just installed the latest version locally (via npm link on current master, sha:#a9f9976), and it is working fine...
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.