43

我想导出一个在 StackBlitz 中完成的 Angular 项目,并使用命令从 Angular CLI 执行它,ng serve就像我们在本地机器上创建的 Angular 项目一样。

4

7 回答 7

54

去做就对了。这里是你需要点击的地方:

stackblitz 截图

于 2018-09-28T18:04:27.430 回答
16

看这里。使用此按钮,您可以下载源代码。

在此处输入图像描述

于 2020-10-21T14:13:42.193 回答
11

要解决此错误:ENOENT: no such file or directory, stat '/.../projectFolder/tsconfig.app.json'

从 StackBlitz 下载项目后,我将 zip 文件复制到了一个文件夹中。我的项目的 tsconfig.app.json 文件位于 src 文件夹中。为了解决上面的错误,我用angular.json 文件中的属性"tsConfig": "tsconfig.app.json"替换了该属性。"tsConfig": "src/tsconfig.app.json"在终端中,我npm install在项目目录中运行以安装所有依赖项。然后我跑去ng serve -o运行服务器,应用程序在我的浏览器中成功打开。

来源:ENOENT:tsconfig.app.json 中没有使用 Angular 4 的此类文件或目录?

编辑:https ://angular.io/start/deployment 的本地构建部分提供了有关如何在本地构建 StackBlitz 应用程序的说明。它基本上是说安装 Angular CLI,创建一个新项目,用下载的 StackBlitz 项目中的 /src 文件夹替换新项目中的 /src 文件夹,最后构建项目。

但是,这对我不起作用,因为它导致缺少模块错误。起作用的是替换新项目文件夹中与 StackBlitz 项目文件夹中的文件匹配的所有文件。运行npm install,,npm build --prod最后ng serve -o

于 2019-08-02T23:28:33.710 回答
7

在此处输入图像描述

  1. 单击该按钮,箭头向下
  2. cd 进入你的项目 cd "你的应用名称"
  3. npm 安装
  4. 服务
于 2018-09-29T07:35:37.850 回答
2

As @gal007, @tamo-studio and @jb-nizet pointed out, you should be able to just download the project, run npm install and ng serve, but this might not work for all projects.

It should work for any project with a current Angular version newer than version 6, I tried with v7 and it worked like a charm.

Your error message in one comment suggests the file tsconfig.json is missing, which you can take form a newly generated project of Angular. To create such a project follow these steps:

  1. Check in package.json which version of Angular your current project uses (look for @angular/core)
  2. install the corresponding version of the angular-cli, e. g. for v4 via npm i -g @angular/cli@^4
  3. run $ ng init in an empty directory
  4. Take the tsconfig.json, move it to your current project and make adjustments if required
  5. Now you can delete the temporairly created project

This should make it run. If it does still not work, look at StackOverflow for the error messages or start a new Question :)

于 2018-11-28T22:40:57.393 回答
2

我还尝试将 StackBlitz Angular 项目导出到我的本地环境,但遇到了一些不同的错误(例如Error: Error on worker #1: TypeError: Cannot read property 'Symbol(Symbol.iterator)' of undefined)——可能是由于我的本地 CLI 所需的文件丢失。

Angular 文档的在本地运行您的应用程序部分(也在@HelloWorldPeace 的回答中指出)对我有用。总结一下:

  1. 从 StackBlitz 下载项目 zip。
  2. 使用 CLI 创建一个空白的本地 Angular 项目:ng new my-project-name
  3. /src将新建项目的文件夹替换/src为 StackBlitz 下载的文件夹
  4. npm install在项目目录和ng serve(或npm start)内

Angular CLI 在严格模式下捕获了一些我必须修复的输入错误(在 StackBlitz 中不必担心它们),但除此之外一切正常。

于 2021-04-27T07:33:09.970 回答
1

StackBlitz 确实不会生成这样的文件。但是目录中的 tsconfig.json 文件表明该目录是 TypeScript 项目的根目录。因此,您可以创建此类文件并将其留空。它允许我从终端编译。 https://www.typescriptlang.org/docs/handbook/tsconfig-json.html

于 2018-10-11T17:33:50.207 回答