我想导出一个在 StackBlitz 中完成的 Angular 项目,并使用命令从 Angular CLI 执行它,ng serve
就像我们在本地机器上创建的 Angular 项目一样。
7 回答
要解决此错误: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
。
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:
- Check in
package.json
which version of Angular your current project uses (look for@angular/core
) - install the corresponding version of the
angular-cli
, e. g. for v4 vianpm i -g @angular/cli@^4
- run
$ ng init
in an empty directory - Take the
tsconfig.json
, move it to your current project and make adjustments if required - 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 :)
我还尝试将 StackBlitz Angular 项目导出到我的本地环境,但遇到了一些不同的错误(例如Error: Error on worker #1: TypeError: Cannot read property 'Symbol(Symbol.iterator)' of undefined
)——可能是由于我的本地 CLI 所需的文件丢失。
Angular 文档的在本地运行您的应用程序部分(也在@HelloWorldPeace 的回答中指出)对我有用。总结一下:
- 从 StackBlitz 下载项目 zip。
- 使用 CLI 创建一个空白的本地 Angular 项目:
ng new my-project-name
/src
将新建项目的文件夹替换/src
为 StackBlitz 下载的文件夹npm install
在项目目录和ng serve
(或npm start
)内
Angular CLI 在严格模式下捕获了一些我必须修复的输入错误(在 StackBlitz 中不必担心它们),但除此之外一切正常。
StackBlitz 确实不会生成这样的文件。但是目录中的 tsconfig.json 文件表明该目录是 TypeScript 项目的根目录。因此,您可以创建此类文件并将其留空。它允许我从终端编译。 https://www.typescriptlang.org/docs/handbook/tsconfig-json.html