简体   繁体   English

在角度项目上使用npm,但在添加角度分量时不显示任何内容

[英]Using npm on angular project but it displays nothing when adding angular component

I am using a angular login example found online that we use npm start to run. 我使用的是在线发现的角度登录示例,我们使用npm start运行。 My problem is when i generate a component and add it to the app.modules.js file, the app doesn't display anything just a white page with a loading... on the top left. 我的问题是,当我生成一个组件并将其添加到app.modules.js文件中时,该应用程序仅显示带有加载内容的白页,而在左上方则不显示任何内容。 can this be because i am using npm? 这可能是因为我正在使用npm吗? when i posted it on stackblitz and added the sidebar component it worked but locally if i add a componenet by ng generate component test and as soon as i add it to the app.modules.js file it shows the white screen but once removed it works perfectly fine. 当我将其发布在stackblitz上并添加了侧边栏组件时,它可以工作,但是如果我通过ng生成一个componenet进行组件测试,则将其添加到app.modules.js文件中时,它会显示白屏,但是一旦移除,它就可以工作了很好。 the stackbliz and origional github link is provided below 下面提供了stackbliz和原始github链接

stackblitz: https://stackblitz.com/edit/angular-ydiywh?file=src%2Fapp%2Fapp.module.ts stackblitz: https ://stackblitz.com/edit/angular-ydiywh ? file = src%2Fapp%2Fapp.module.ts

github: http://jasonwatmore.com/post/2018/06/14/nodejs-mongodb-simple-api-for-authentication-registration-and-user-management github: http : //jasonwatmore.com/post/2018/06/14/nodejs-mongodb-simple-api-for-authentication-registration-and-user-management

when i run ng serve --open i get the following error 当我运行ng serve --open时出现以下错误

error after installing module 安装模块后出现错误

ENOENT: no such file or directory, stat '/Users/xxx/Library/Mobile Documents/com~apple~CloudDocs//src/tsconfig.app.json'
Error: ENOENT: no such file or directory, stat '/Users/xxx/Library/Mobile Documents/com~apple~CloudDocs/src/tsconfig.app.json'
    at Object.statSync (fs.js:815:3)
    at AngularCompilerPlugin._setupOptions (/Users/xxx/Library/Mobile Documents/com~apple~CloudDocs/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:96:16)
    at new AngularCompilerPlugin (/Users/xxx/Library/Mobile Documents/com~apple~CloudDocs/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:61:14)
    at _createAotPlugin (/Users/xxx/Library/Mobile Documents/com~apple~CloudDocs/node_modules/@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs/typescript.js:41:12)
    at Object.getNonAotConfig (/Users/xxx/Library/Mobile Documents/com~apple~CloudDocs/node_modules/@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs/typescript.js:47:19)
    at BrowserBuilder.buildWebpackConfig (/Users/xxx/Library/Mobile Documents/com~apple~CloudDocs/node_modules/@angular-devkit/build-angular/src/browser/index.js:82:37)
    at DevServerBuilder.buildWebpackConfig (/Users/xxx/Library/Mobile Documents/com~apple~CloudDocs/node_modules/@angular-devkit/build-angular/src/dev-server/index.js:111:46)
    at MergeMapSubscriber.check_port_1.checkPort.pipe.operators_1.concatMap [as project] (/Users/xxx/Library/Mobile Documents/com~apple~CloudDocs/node_modules/@angular-devkit/build-angular/src/dev-server/index.js:38:40)
    at MergeMapSubscriber._tryNext (/Users/xxx/Library/Mobile Documents/com~apple~CloudDocs/node_modules/rxjs/internal/operators/mergeMap.js:65:27)
    at MergeMapSubscriber._next (/Users/xxx/Library/Mobile Documents/com~apple~CloudDocs/node_modules/rxjs/internal/operators/mergeMap.js:55:18)
    at MergeMapSubscriber.Subscriber.next (/Users/xxx/Library/Mobile Documents/com~apple~CloudDocs/node_modules/rxjs/internal/Subscriber.js:64:18)
    at TapSubscriber._next (/Users/xxx/Library/Mobile Documents/com~apple~CloudDocs/node_modules/rxjs/internal/operators/tap.js:62:26)
    at TapSubscriber.Subscriber.next (/Users/xxx/Library/Mobile Documents/com~apple~CloudDocsnode_modules/rxjs/internal/Subscriber.js:64:18)
    at MergeMapSubscriber.notifyNext (/Users/xxx/Library/Mobile Documents/com~apple~CloudDocsnode_modules/rxjs/internal/operators/mergeMap.js:84:26)
    at InnerSubscriber._next (/Users/xxx/Library/Mobile Documents/com~apple~CloudDocs/node_modules/rxjs/internal/InnerSubscriber.js:25:21)
    at InnerSubscriber.Subscriber.next (/Users/xxx/Library/Mobile/node_modules/rxjs/internal/Subscriber.js:64:18)

.angular.cli file .angular.cli文件

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "new-cli": {
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist",
            "index": "src/index.html",
            "main": "src/main.ts",
            "tsConfig": "src/tsconfig.app.json",
            "polyfills": "src/polyfills.ts",
            "assets": [
              "src/assets"
            ],
            "styles": [],
            "scripts": []
          },
          "configurations": {
            "production": {
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "new-cli:build"
          },
          "configurations": {}
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "new-cli:build"
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [],
            "exclude": []
          }
        }
      }
    },
    "new-cli-e2e": {
      "root": "e2e",
      "sourceRoot": "e2e",
      "projectType": "application"
    }
  },
  "defaultProject": "new-cli"
}

error in chrome inspect when adding component and running npm start 添加组件并运行npm start时chrome inspect错误

Uncaught Error: Unexpected module 'SidebarModule' declared by the 
 module 'AppModule'. Please add a @Pipe/@Directive/@Component 
 annotation. at syntaxError 
 (webpack:///./node_modules/@angular/compiler/fesm5/compiler.js?:1270) 
 at eval 
 (webpack:///./node_modules/@angular/compiler/fesm5/compiler.js?:10888) 
 at Array.forEach (<anonymous>) at 
 CompileMetadataResolver.getNgModuleMetadata 
 (webpack:///./node_modules/@angular/compiler/fesm5/compiler.js?:10870) 
 at JitCompiler._loadModules 
 (webpack:///./node_modules/@angular/compiler/fesm5/compiler.js?:24112) 
 at JitCompiler._compileModuleAndComponents 
 (webpack:///./node_modules/@angular/compiler/fesm5/compiler.js?:24093) 
 at JitCompiler.compileModuleAsync 
 (webpack:///./node_modules/@angular/compiler/fesm5/compiler.js?:24053) 
 at CompilerImpl.compileModuleAsync 
 (webpack:///./node_modules/@angular/platform-browser- 
 dynamic/fesm5/platform-browser-dynamic.js?:158) at 
 PlatformRef.bootstrapModule 
 (webpack:///./node_modules/@angular/core/fesm5/core.js?:4649) at eval 
 (webpack:///./src/main.ts?:6)

Install the Angular CLI: 安装Angular CLI:

npm install @angular/cli

Then run this from the app directory. 然后从应用程序目录运行它。 It should open a browser to localhost:4200 它应该打开浏览器到localhost:4200

ng serve --open
npm install --save-dev @angular-devkit/build-angular

这应该可以解决您的开发套件错误,这是角度6中引入的新依赖关系,必须保存为开发依赖关系

So here are the steps to reproduce for your 'local' stackblitz to work: 因此,以下是为您的“本地”堆栈闪电重现而工作的步骤:

1 - generate your project with ng new myApp 1-使用ng new myApp生成项目
2 - download the stackblitz project via the export button, then extract the files inside of the compressed folder. 2-通过导出按钮下载stackblitz项目,然后将文件解压缩到压缩文件夹中。
3 - in the extracted folder, go to the src folder, then inside of it click on the second src folder. 3-在提取的文件夹中,转到src文件夹,然后在其中单击第二个src文件夹。
4 - copy the app and the main.ts file and paste them to the first src folder. 4-复制appmain.ts文件,并将它们粘贴到第一个src文件夹中。
5 - open the typings.d file in the second src folder and copy the line inside. 5-打开第二个src文件夹中的typings.d文件,然后在其中复制该行。 and paste this line in the typings.d file in the first src folder. 并将此行粘贴到第一个src文件夹中的typings.d文件中。
6 - delete the second src folder. 6-删除第二个src文件夹。
7 - replace the src folder in your project root with the one from the extracted folder. 7-用解压缩后的文件夹中的一个替换项目根目录中的src文件夹。
8 - run this command in your project root: npm install --save ng-sidebar 8-在您的项目根目录中运行以下命令: npm install --save ng-sidebar
9 - run npm start 9-运行npm start

You can now create how many components you want this will still works. 现在,您可以创建所需的组件数量,这些组件仍然可以使用。

So I went to the site you cited and downloaded the github project. 因此,我去了您引用的站点并下载了github项目。

I followed the instructions on the page and was able to run it with no issue. 我按照页面上的说明进行操作,并且能够正常运行。

I tried to add a component via "ng" and was unable to. 我试图通过“ ng”添加组件,但无法。 I kept getting a variety of errors related to angular.json not being able to be located and so on. 我不断收到各种有关angular.json无法定位的错误,依此类推。 I'm not sure what you did to get the component in there, but it seems like that is related to the problem. 我不确定要如何将组件放入其中,但是似乎与问题有关。 The cli cannot run this project out of the box it seems to require the use of npm. cli无法开箱即用地运行此项目,它似乎需要使用npm。

After looking through some of the source it seems that this is Angular on Webpack, so the CLI won't work for you. 在浏览了一些资源之后,似乎这是Webpack上的Angular,因此CLI不适用于您。 It won't allow you to create components either. 它也不允许您创建组件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM