在本地运行现有Angular项目

时间:2018-05-07 11:13:39

标签: node.js angular typescript npm webpack

我是Angular的新手,我正试图在我的机器上运行Angular的现有项目。我做了很多测试并且跟着很多文章。但无法运行我的项目。

我有这样的项目文件:

enter image description here

我在我的系统上安装了nodejs。 并根据文章按照以下说明进行操作:

将目录更改为我们的仓库

cd myproject

根据项目自述文件安装Cli。

npm install -g @ angular / cli @ 1.3.2

使用npm

安装repo

npm install

安装TypeScript打字

npm run typings-install - 给出错误:npm ERR!缺少脚本:typings-install

然后我尝试以下方法:

npm install --global 以下是:

webpack (npm install --global webpack)
webpack-dev-server (npm install --global webpack-dev-server)
karma (npm install --global karma-cli)
protractor (npm install --global protractor)
typings (npm install --global typings)
typescript (npm install --global typescript)

启动服务器

npm start

- 提供多条错误消息: 如:

npm ERR! code ELIFECYCLE

- 为此我试过" npm cache clean"然后删除" node_modules"然后使用以下命令再次安装软件包:" npm install --save"

然后再次尝试:npm start它给了我同样的错误" npm ERR! code ELIFECYCLE"

此外,此错误消息:

Cannot find module 'webpack/lib/node/NodeTemplatePlugin'

为此,我尝试了#34; npm uninstall -g webpack" 然后:npm install --save-dev webpack webpack-cli html-webpack-plugin webpack-dev-server webpack-dev-middleware from this:Error: Cannot find module 'webpack/lib/node/NodeTemplatePlugin'

尝试再次运行它:

这次它给了我以下错误:

ERROR in ./node_modules/raw-loader!./node_modules/@angular/cli/node_modules/post
css-loader/lib??embedded!./node_modules/sass-loader/lib/loader.js??ref--8-3!./sr
c/styles.scss
Module build failed: Error: Cannot find module 'node-sass'

为此" Cannot find module 'node-sass'"我再次进行了搜索:

找到此命令:npm install node-sass

我尝试了,然后再次尝试重新开始

现在我收到了ERROR in No NgModule metadata found for 'AppModule'.

为此,我尝试了以下来自git cli问题8798

删除node_modules文件夹

rm -rf node_modules

删除网络包

npm remove webpack

清理npm cahe

npm cache clean --force

安装最新版本的angular cli

npm install --save-dev @angular/cli@latest

安装依赖项

npm install

现在它只是在测试

npm start our ng serve

现在它开始给我:无法找到本地工作区文件(' angular.json')并且根本无法工作。 为了解决这个问题:我做了:n g update @angular/cli --migrate-only --from=1.7.4

删除错误:"无法找到本地工作区文件(' angular.json')"但现在它给了我错误

ERROR in src/app/web-player/albums/album-context-menu/album-context-menu.compon
nt.ts(13,14): error TS2515: Non-abstract class 'AlbumContextMenuComponent' does
not implement inherited abstract member 'getAllTracks' from class 'ContextMenuC
mponent<Album>'.
src/app/web-player/artists/artist-context-menu/artist-context-menu.component.ts
13,14): error TS2515: Non-abstract class 'ArtistContextMenuComponent' does not
mplement inherited abstract member 'getAllTracks' from class 'ContextMenuCompon
nt<Artist>'.
src/app/web-player/context-menu/context-menu.component.ts(58,34): error TS2304:
Cannot find name 'TrackList'.
src/app/web-player/playlists/playlist-context-menu/playlist-context-menu.compon
nt.ts(15,14): error TS2515: Non-abstract class 'PlaylistContextMenuComponent' d
es not implement inherited abstract member 'getAllTracks' from class 'ContextMe
uComponent<Playlist>'.

我在这里缺少什么?我从3天开始尝试了很多文章但是无法运行它。

另外,我看到了不同类型的警告和消息。 enter image description here

项目中的自述文件:

# Client

This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 1.3.2.

## Development server

Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files.

## Code scaffolding

Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`.

## Build

Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `-prod` flag for a production build.

## Running unit tests

Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io).

## Running end-to-end tests

Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/).
Before running the tests make sure you are serving the app via `ng serve`.

## Further help

To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md).

Package.json文件:

{
  "name": "client",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve --proxy-config proxy.conf.json --host 0.0.0.0",
    "build": "ng build --prod --sourcemaps --build-optimizer",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^5.1.2",
    "@angular/common": "^5.1.2",
    "@angular/compiler": "^5.1.2",
    "@angular/core": "^5.1.2",
    "@angular/forms": "^5.1.2",
    "@angular/http": "^5.1.2",
    "@angular/platform-browser": "^5.1.2",
    "@angular/platform-browser-dynamic": "^5.1.2",
    "@angular/router": "^5.1.2",
    "bootstrap": "^4.0.0-beta",
    "chart.js": "^2.7.0",
    "copy-to-clipboard": "^3.0.8",
    "core-js": "^2.5.1",
    "hammerjs": "^2.0.8",
    "moment": "^2.18.1",
    "ng-lazyload-image": "^3.3.3",
    "ngx-color-picker": "^4.3.4",
    "normalize.css": "^7.0.0",
    "perfect-scrollbar": "^0.8.1",
    "popper.js": "^1.12.5",
    "raven-js": "^3.18.1",
    "rxjs": "^5.4.2",
    "svg4everybody": "^2.1.4",
    "tooltip.js": "^1.1.5",
    "zone.js": "^0.8.18"
  },
  "devDependencies": {
    "@angular/cli": "^1.6.2",
    "@angular/compiler-cli": "^5.1.2",
    "@angular/language-service": "^5.1.2",
    "@types/hammerjs": "^2.0.35",
    "@types/jasmine": "~2.5.53",
    "@types/jasminewd2": "^2.0.3",
    "@types/node": "~6.0.60",
    "@types/popper.js": "^1.10.1",
    "@types/youtube": "0.0.31",
    "@types/clipboard": "^1.5.35",
    "cheerio": "^1.0.0-rc.2",
    "codelyzer": "~3.1.1",
    "gulp": "^3.9.1",
    "gulp-clean": "^0.3.2",
    "gulp-filter": "^5.0.0",
    "gulp-rename": "^1.2.2",
    "gulp-svgmin": "^1.2.3",
    "gulp-svgstore": "^6.1.0",
    "jasmine-core": "~2.6.2",
    "jasmine-spec-reporter": "~4.1.0",
    "karma": "^1.7.1",
    "karma-chrome-launcher": "~2.1.1",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "material-design-icons": "^3.0.1",
    "protractor": "~5.1.2",
    "ts-node": "~3.2.0",
    "tslint": "~5.7.0",
    "typescript": "~2.4.2",
    "webpack-bundle-analyzer": "^2.9.0"
  }
}

5 个答案:

答案 0 :(得分:4)

那应该容易得多...

按原样保存项目文件

运行npm install

由于您拥有package.json文件,它将读取并安装所有依赖项。

然后根据需要运行npm audit fix(终端会告诉您)。

祝你好运!

答案 1 :(得分:1)

尝试ng-serve --open 它将编译您的项目并直接在浏览器中打开

答案 2 :(得分:1)

运行以下命令

 npm uninstall -g @angular/cli
 npm cache verify
 npm install -g @angular/cli@next
 npm update

然后

 ng serve 

我希望现在有效。如果您在遇到任何错误时发表评论。

答案 3 :(得分:0)

将文件.angular-cli.json重命名为angular.json,然后重新运行ng serve --open命令。

答案 4 :(得分:0)

  1. 更改本地目录的路径

cd my-repo

  1. npm install

  2. ng serveng serve --open

然后您将找到Localhost。

要清除缓存:

npm cache clean
相关问题