ERROR in ./ansi-html 1:0 Module parse failed: Unex

2019-07-23 17:39发布

问题:

I am learning angular js. When I run ng serve --open I get below error

ERROR in ./ansi-html 1:0
Module parse failed: Unexpected character '#' (1:0)
You may need an appropriate loader to handle this file type
> #!/bin/sh
| basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")

angular CLI version is 6.2.0

node version is 8.11.4

npm version is 6.4.1

ansi-html file is as

#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")

case `uname` in
    *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac

if [ -x "$basedir/node" ]; then
  "$basedir/node"  "$basedir/node_modules/ansi-html/bin/ansi-html" "$@"
  ret=$?
else 
  node  "$basedir/node_modules/ansi-html/bin/ansi-html" "$@"
  ret=$?
fi
exit $ret

If I remove first line then error is

ERROR in ./ansi-html 1:18
Module parse failed: Unexpected token (1:18)
You may need an appropriate loader to handle this file type.
> basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
| case `uname` in
i ?wdm?: Failed to compile.

回答1:

Same Problem here with latest versions on windows 10 machine:

NPM : 6.4.1
Angular CLI: 7.3.4
Node: 10.15.2
OS: win32 x64
Angular: 7.2.7
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.13.4
@angular-devkit/build-angular     0.13.4
@angular-devkit/build-optimizer   0.13.4
@angular-devkit/build-webpack     0.13.4
@angular-devkit/core              7.3.4
@angular-devkit/schematics        7.3.4
@angular/cli                      7.3.4
@ngtools/webpack                  7.3.4
@schematics/angular               7.3.4
@schematics/update                0.13.4
rxjs                              6.3.3
typescript                        3.2.4
webpack                           4.29.0


回答2:

Alright everyone! I faced same problem earlier this year on my windows machine(Windows 10 Enterprise).

Cause?

I have no idea why the hell this happened.

Solution?

You have to completely uninstall node.js from your machine.

How i solved mine?

  1. First, i did a cache clean using this command: "npm cache clean --force" without quotes.
  2. Second, i uninstalled node.js using iobit uninstaller software(i'm just being explicit it doesn't matter).

  3. Third, i deleted nmp-cache folder in C:\Users\YOURNAME\AppData\Roaming

  4. Fourth, i deleted .npmrc file from users\USER DIRECTORY(if you can't see this file, you need to show hidden files, folders, and drives from file explorer options).
  5. Fifth, i deleted all ionic files on same location(users\USER DIRECTORY ionic was previously installed).

Now, restart your computer; visit https://nodejs.org and download a fresh node.js installer, during the installation you'll be asked if you'd like to install additional tools for node.js, please skip and proceed to finish. Confirm you have successfully installed node.js, run this command: "node --version && npm --version" without quotes. You should get something like this:

v11.11.0

6.7.0

If everything is all good at this point, feel free to install your angular; command: "npm install -g @angular/cli" without quotes(the -g flag will install it globally so you could create a new angular project from anywhere on your pc). Again, confirm installation; run: "ng --version", you should have something like this:

Angular CLI: 7.3.6

Node: 11.11.0

OS: win32 x64

Angular: 7.2.9

Go ahead and create a new angular project, just before you do that; be sure you are currently in the right directory. Command: "ng new project-name" without quotes(project-name is what you wanna name your project). After a successful installation run your project by opening the project directory e.g "cd project-name" without quotes and then "ng serve --open"(--open flag opens the project in your default web browser, will take a few seconds).

Cheers.



标签: angularjs npm