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.PORT
是 typed 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/