javascript - 背包示例 "with-typescript"无法编译

标签 javascript node.js typescript

Node -v => v8.9.4
npm -v => 5.6.0

想要安装this示例。
示例中有错误或者我做错了什么?
我相信要安装该示例,您需要做的就是克隆并运行 npm install,但完成后:

mkdir test
cd test
git clone https://github.com/palmerhq/backpack.git
cd ./backpack/examples/with-typescript/
npm install
npm run dev

我收到了:

| backpack-examples-with-typescript@0.5.0 dev ~/test/backpack/examples/with-typescript  
| backpack dev  


[at-loader] Using typescript@2.7.1 from typescript and "tsconfig.json" from ~/test/backpack/examples/with-typescript/tsconfig.json.  


[at-loader] Checking started in a separate process...  

[at-loader] Checking finished with 1 errors  


ERROR  Failed to compile with 1 errors 19:38:08  

error  

加上

[at-loader] ./src/main.ts:33:35  
TS2322: Type 'string | 3000' is not assignable to type 'number'.  
Type 'string' is not assignable to type 'number'.  

module.js:540  
throw err;  
^  

Error: Cannot find module '~/test/backpack/examples/with-typescript/build/main.js'  
at Function.Module._resolveFilename (module.js:538:15)  
at Function.Module._load (module.js:468:25)  
at Function.Module.runMain (module.js:684:10)  
at startup (bootstrap_node.js:187:16)  
at bootstrap_node.js:608:3

我写了this question他们几天前就发出了轨道,但没有人回答

最佳答案

this line (33:35) 处出错的源代码。 process.env.PORTtyped as string在 NodeJS 类型声明中。但是,getPort 必须返回一个数字。尝试使用以下内容更改该行:

private getPort = (): number => parseInt(process.env.PORT) || 3000;

出现无法找到 js 文件的额外错误可能是因为 at-loader 编译失败,因此没有输出该文件。

关于javascript - 背包示例 "with-typescript"无法编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48600247/

相关文章:

javascript - 在 node.js 中生成并终止一个进程

javascript - 使用 Nodejs Web 服务器但没有框架对用户进行身份验证

javascript - 将字符串拆分为从 "] "开始、以 "As"结尾的子字符串

node.js - 如何在 typescript 中创建泛型类型参数的实例

javascript - 定义 Kendo UI 默认值和功能

javascript - Dogfooding 我们自己的限速 API

javascript - 复选框在 Accordion 的 ng-repeat 中被禁用

javascript - 咕噜声 : Loading dependencies takes several minutes

python - 遍历 JSON - 需要逻辑来计算值的总和

angular - 如何从 Angular 4的文件上传输入中获取路径