angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

ng serve "webpack: Failed to compile." If path contains folder name starting with "!"

Open ppeterka opened this issue 9 years ago • 5 comments

Title sums it up: if the path to the project contains a folder whose name starts with an exclamation mark (!) character, ng serve fails with webpack: Failed to compile.

Workaround: Renaming the offending folder by removing the problematic character solves issue.

Details:

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

Versions.

@angular/cli: 1.1.2
node: 8.1.2
os: win32 x64
@angular/animations: 4.2.3
@angular/common: 4.2.3
@angular/compiler: 4.2.3
@angular/core: 4.2.3
@angular/forms: 4.2.3
@angular/http: 4.2.3
@angular/platform-browser: 4.2.3
@angular/platform-browser-dynamic: 4.2.3
@angular/router: 4.2.3
@angular/cli: 1.1.2
@angular/compiler-cli: 4.2.3
@angular/language-service: 4.2.3

Might be also relevant: Windows 10, 64 bit

Note: I previously had out of date Node 6.1.0, and older npm (problem happened with those versions too), but before starting to debug I updated everything to make sure all is up to date...

Repro steps.

  • Create a folder named !correct
  • Follow steps in Angular QuickStart guide (so that it would create a !correct/my-app folder)
  • ng serve --open throws error
  • rename !correct folder to correct
  • ng serve --open works as expected

The log given by the failure.

Failure part

C:\Users\ppete\Documents\DEV\!Angular\test1>ng serve --open
** NG Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200 **
 10% building modules 6/9 modules 3 active ...1\node_modules\webpack\hot\emitter.jswebpack: wait until bundle finished: /                                    Hash: 5e52a4b2b9800e47679f
Time: 5094ms
chunk    {0} main.bundle.js, main.bundle.js.map (main) 40 bytes {3} [initial] [rendered]
chunk    {1} styles.bundle.js, styles.bundle.js.map (styles) 28 bytes {4} [initial] [rendered]
chunk    {2} polyfills.bundle.js, polyfills.bundle.js.map (polyfills) 28 bytes {4} [initial] [rendered]
chunk    {3} vendor.bundle.js, vendor.bundle.js.map (vendor) 302 kB [initial] [rendered]
chunk    {4} inline.bundle.js, inline.bundle.js.map (inline) 0 bytes [entry] [rendered]

ERROR in multi webpack-dev-server/client?http://localhost:4200 ./src/main.ts
Module not found: Error: Can't resolve 'C:\Users\ppete\Documents\DEV\' in 'C:\Users\ppete\Documents\DEV\!Angular\test1\node_modules\@angular\cli\models\webpack-configs'
 @ multi webpack-dev-server/client?http://localhost:4200 ./src/main.ts

ERROR in multi ./src/polyfills.ts
Module not found: Error: Can't resolve 'C:\Users\ppete\Documents\DEV\' in 'C:\Users\ppete\Documents\DEV\!Angular\test1\node_modules\@angular\cli\models\webpack-configs'
 @ multi ./src/polyfills.ts

ERROR in multi ./src/styles.css
Module not found: Error: Can't resolve 'C:\Users\ppete\Documents\DEV\' in 'C:\Users\ppete\Documents\DEV\!Angular\test1\node_modules\@angular\cli\models\webpack-configs'
 @ multi ./src/styles.css

ERROR in   Error: Child compilation failed:
  Entry module not found: Error: Can't resolve 'C:\Users\ppete\Documents\DEV\' in 'C:\Users\ppete\Documents\DEV\!Angular  \test1\node_modules\@angular\cli\models\webpack-configs':
  Error: Can't resolve 'C:\Users\ppete\Documents\DEV\' in 'C:\Users\ppete\Documents\DEV\!Angular\test1\node_modules\@ang  ular\cli\models\webpack-configs'

  - compiler.js:76
    [test1]/[html-webpack-plugin]/lib/compiler.js:76:16

  - Compiler.js:291 Compiler.<anonymous>
    [test1]/[webpack]/lib/Compiler.js:291:10

  - Compiler.js:494
    [test1]/[webpack]/lib/Compiler.js:494:13

  - Tapable.js:138 next
    [test1]/[tapable]/lib/Tapable.js:138:11

  - CachePlugin.js:62 Compiler.<anonymous>
    [test1]/[webpack]/lib/CachePlugin.js:62:5

  - Tapable.js:142 Compiler.applyPluginsAsyncSeries
    [test1]/[tapable]/lib/Tapable.js:142:13

  - Compiler.js:491
    [test1]/[webpack]/lib/Compiler.js:491:10

  - Tapable.js:131 Compilation.applyPluginsAsyncSeries
    [test1]/[tapable]/lib/Tapable.js:131:46

  - Compilation.js:645 self.applyPluginsAsync.err
    [test1]/[webpack]/lib/Compilation.js:645:19

  - Tapable.js:131 Compilation.applyPluginsAsyncSeries
    [test1]/[tapable]/lib/Tapable.js:131:46

  - Compilation.js:636 self.applyPluginsAsync.err
    [test1]/[webpack]/lib/Compilation.js:636:11

  - Tapable.js:131 Compilation.applyPluginsAsyncSeries
    [test1]/[tapable]/lib/Tapable.js:131:46

  - Compilation.js:631 self.applyPluginsAsync.err
    [test1]/[webpack]/lib/Compilation.js:631:10

  - Tapable.js:131 Compilation.applyPluginsAsyncSeries
    [test1]/[tapable]/lib/Tapable.js:131:46

  - Compilation.js:627 sealPart2
    [test1]/[webpack]/lib/Compilation.js:627:9

  - Tapable.js:131 Compilation.applyPluginsAsyncSeries
    [test1]/[tapable]/lib/Tapable.js:131:46


webpack: Failed to compile.

Testing workaround after renaming folder

C:\Users\ppete\Documents\DEV\Angular\test1>ng serve --open
** NG Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200 **
 10% building modules 6/9 modules 3 active ...ode_modules\style-loader\addStyles.jswebpack: wait until bundle finished: /             Hash: 207adb8e1440eb67702b
Time: 13703ms
chunk    {0} polyfills.bundle.js, polyfills.bundle.js.map (polyfills) 160 kB {4} [initial] [rendered]
chunk    {1} main.bundle.js, main.bundle.js.map (main) 5.34 kB {3} [initial] [rendered]
chunk    {2} styles.bundle.js, styles.bundle.js.map (styles) 10.5 kB {4} [initial] [rendered]
chunk    {3} vendor.bundle.js, vendor.bundle.js.map (vendor) 2.18 MB [initial] [rendered]
chunk    {4} inline.bundle.js, inline.bundle.js.map (inline) 0 bytes [entry] [rendered]
webpack: Compiled successfully.

Desired functionality.

Folder names prefixed with an exclamation mark should work as expected.

(Fun fact: These odd exclamation mark issues keep finding me... I found one in Eclipse too)

ppeterka avatar Jun 17 '17 12:06 ppeterka

Some more details: The bug seems to be rooted in webpack (sorry, I really just started learning node and Angular, so I'm a bit slow debugging all this)

Grepping for "!", the results make me highly suspect that at the create function in the *ModuleFactory classes, and their hackish handling of multiple requests in one string is the cause... I wonder why the original author didn't use a character that is obviously not valid in a path string, like the pipe "|"... Or at least it could have been a constant defined somewhere - now this will require quite an effort to correct...

ContextModuleFactory, starting from line 47

var idx = request.lastIndexOf("!");
  if(idx >= 0) {
  loaders = request.substr(0, idx + 1);
  for(var i = 0; i < loaders.length && loaders[i] === "!"; i++) {
    loadersPrefix += "!";
  }
  loaders = loaders.substr(i).replace(/!+$/, "").replace(/!!+/g, "!");
  if(loaders === "") loaders = [];
  else loaders = loaders.split("!");
  resource = request.substr(idx + 1);
} else {
  loaders = [];
  resource = request;
}

The fact that the bug occurs with all exclamation marks in paths, and not just those that are at the start of a path element - i.e. C:\stuff\Ang!ular\etc is affected too - seems to support my suspicion about the above code...

EDIT: Meh, I see this all goes down to AMD - I wonder how could people who do something like that in scale have such a wrong decision to use the exclamation mark as a separator...

ppeterka avatar Jun 25 '17 19:06 ppeterka

You are right that this is rooted in webpack. It is a current limitation Angular CLI incurs of using webpack.

Webpack uses it for a couple of things, including chaining loaders.

I don't know of any solutions that allow using ! in directory names currently.

filipesilva avatar Jun 26 '17 12:06 filipesilva

@filipesilva Thanks for taking a look at it. As the root of the problem is actually a conceptual issue that is not likely to get fixed anytime soon - being in the AMD spec, meaning the fix would have to be followed by the implementations...

ppeterka avatar Jun 26 '17 13:06 ppeterka

I'm sorry, but this issue is not caused by Angular CLI.

alan-agius4 avatar Dec 04 '18 14:12 alan-agius4

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.