英文:
Error when adding my npm module to imports
问题
我安装并在Stackblitz中引用npm Angular2-wizard后,出现以下错误,您能帮助我理解原因吗?
我有这个Stackblitz,我安装了angular2-wizard。安装完后,我像文档中建议的那样在test.module.ts文件中引用它:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { StripeComponent } from './stripe/stripe.component';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { NgxStripeModule } from 'ngx-stripe';
import { FormWizardModule } from 'angular2-wizard';
@NgModule({
imports: [
CommonModule,
FormsModule,
ReactiveFormsModule,
FormWizardModule
],
declarations: [StripeComponent],
exports: [
StripeComponent
]
})
export class TestModule { }
我在屏幕上看到以下错误:
英文:
Any help in understanding why I'm getting this error below installing and then referencing npm Angular2-wizard in my Stackblitz.
I have this Stackblitz and I installed angular2-wizard. After I installed it I referenced it in my test.module.ts file like this (according to the docs):
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { StripeComponent } from './stripe/stripe.component';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { NgxStripeModule } from 'ngx-stripe';
import { FormWizardModule } from 'angular2-wizard';
@NgModule({
imports: [
CommonModule,
FormsModule,
ReactiveFormsModule,
FormWizardModule
],
declarations: [StripeComponent],
exports: [
StripeComponent
]
})
export class TestModule { }
<!-- end snippet -->
I see this error on the screen:
答案1
得分: 1
我有一种预感,这是由angular2-wizard
从他们的库中的index.ts
导出这些组件的方式引起的:
export * from './src/wizard.component';
export * from './src/wizard-step.component';
https://github.com/maiyaporn/angular2-wizard/blob/master/index.ts
当Stackblitz初始化时,它将代码封装/隔离到webcontainer环境中。当它尝试解析'./src/wizard.component'
路由时,它很可能查看项目中定义的根src
目录,而不是正确的node_modules/angular2-wizard/src
目录。这可能解释了为什么在本地运行正常,但在这里却不行。
我认为修复此问题的方法是将src
目录重命名为其他名称,但似乎Stackblitz对于Angular项目存在一个bug,因为它始终尝试引用/~/src/main.ts
,而不管main.ts
所在的目录名称如何:
Cannot read file '/~/src/main.ts': Error: ENOENT: No such file or directory., '/~/src/main.ts'. The file is in the program because: Root file specified for compilation
我将在Stackblitz上提出一个错误报告(在我提出后,将链接到这个问题),但目前看起来你运气不太好。
https://github.com/stackblitz/core/issues/2456
https://github.com/stackblitz/core/issues/2455
英文:
I have a hunch that this is caused by the the manner in which angular2-wizard
are exporting these components from their library in index.ts
:
export * from './src/wizard.component';
export * from './src/wizard-step.component';
https://github.com/maiyaporn/angular2-wizard/blob/master/index.ts
When Stackblitz initializes it encapsulates/sandboxes the code into a webcontainer environment. When it tries to resolve the './src/wizard.component'
routes it is most likely looking at the root src
directory that is defined in your project instead of the correct node_modules/angular2-wizard/src
directory. This may explain why this works for you locally but not here.
I figured that the fix for this would be to rename the src
directory to something else, however it appears that there may be a bug in Stackblitz for Angular projects because it always tries to reference /~/src/main.ts
regardless of the name of the directory main.ts is in:
Cannot read file '/~/src/main.ts': Error: ENOENT: No such file or directory., '/~/src/main.ts'. The file is in the program because: Root file specified for compilation
I am going to raise a bug for this against Stackblitz (will link to this question when I have), but for now it looks like you are out of luck.
https://github.com/stackblitz/core/issues/2456<br>
https://github.com/stackblitz/core/issues/2455
答案2
得分: -1
请参考以下内容:
而不是使用 npm
安装 angular2-wizard
尝试下载最新发布版本的源代码,然后将src/
目录中的文件(包括 wizard.component.ts
、wizard-step.component.ts
、wizard.component.spec.ts
、wizard-step.component.spec.ts
)复制到你的 src/
目录中。
与将 angular2-wizard 安装为一个包不同,你只需将这些组件添加到你的项目中。
英文:
Rather than using npm
to install angular2-wizard
Try downloading the source of the latest release and copying the files in the src/
directory (contains the files wizard.component.ts
, wizard-step.component.ts
, wizard.component.spec.ts
, wizard-step.component.spec.ts
) to your src/
directory.
Instead of installing angular2-wizard as a package, you're just adding the components to your project.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论