【发布时间】:2021-12-31 15:27:00
【问题描述】:
我正在尝试在 Angular web app 中使用 Tensorflow 的 DANFO.js 库(使用 Ionic 组件,但这无关紧要)。
- 我只运行了命令:
npm install danfojs --save和npm install @tensorflow/tfjs-node --save - 我在 Angular
Service中尝试了各种导入,例如:import 'danfojs';、import { DataFrame } from 'danfojs';甚至仅根据 related question to this topic 我可以找到:import { DataFrame } from 'danfojs/dist/core/frame'; - 以上所有示例均无效
- 我什至尝试在
app.module中导入 DANFO.js 而不做任何更改
而且我总是收到此错误消息(其余错误正在编辑中):
Build at: 2021-11-21T21:38:12.984Z - Hash: 5f05ff4be188e54ccaaf - Time: 10137ms
[ng] Error: node_modules/danfojs/types/core/generic.d.ts:75:26 - error TS2307: Cannot find module '@tensorflow/tfjs-node' or its corresponding type declarations.
[ng] 75 get tensor(): import("@tensorflow/tfjs-node").Tensor1D | import("@tensorflow/tfjs-node").Tensor2D;
[ng] ~~~~~~~~~~~~~~~~~~~~~~~
[ng] Error: node_modules/danfojs/types/core/generic.d.ts:75:69 - error TS2307: Cannot find module '@tensorflow/tfjs-node' or its corresponding type declarations.
[ng] 75 get tensor(): import("@tensorflow/tfjs-node").Tensor1D | import("@tensorflow/tfjs-node").Tensor2D;
如何在 Angular 应用程序中(特别是在服务中)使用 DANFO.js?
编辑:
我根据下面的答案将代码添加到tsconfig.js,不幸的是错误仍然存在。这是我的tsconfig.js 文件:
/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"importHelpers": true,
"target": "es2015",
"module": "es2020",
"lib": ["es2018", "dom"],
"skipLibCheck": true
},
"angularCompilerOptions": {
"enableI18nLegacyMessageIdFormat": false,
"strictInjectionParameters": true,
"strictInputAccessModifiers": true,
"strictTemplates": true
}
}
整个错误代码太长了,不适合 VS Code 终端(只有数百个错误):
[ng] 84 to_csv(options?: CsvOutputOptionsNode): string | void;
[ng] ~~~~~~~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:84:20 - error TS1109: Expression expected.
[ng] 84 to_csv(options?: CsvOutputOptionsNode): string | void;
[ng] ~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:84:22 - error TS2693: 'CsvOutputOptionsNode' only refers to a type, but is being used as a value here.
[ng] 84 to_csv(options?: CsvOutputOptionsNode): string | void;
[ng] ~~~~~~~~~~~~~~~~~~~~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:84:43 - error TS1005: ';' expected.
[ng] 84 to_csv(options?: CsvOutputOptionsNode): string | void;
[ng] ~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:84:45 - error TS2693: 'string' only refers to a type, but is being used as a value here.
[ng] 84 to_csv(options?: CsvOutputOptionsNode): string | void;
[ng] ~~~~~~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:84:54 - error TS2532: Object
is possibly 'undefined'.
[ng] 84 to_csv(options?: CsvOutputOptionsNode): string | void;
[ng] ~~~~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:84:58 - error TS1109: Expression expected.
[ng] 84 to_csv(options?: CsvOutputOptionsNode): string | void;
[ng] ~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:85:5 - error TS2304: Cannot find name 'to_json'.
[ng] 85 to_json(options?: {
[ng] ~~~~~~~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:85:13 - error TS2304: Cannot
find name 'options'.
[ng] 85 to_json(options?: {
[ng] ~~~~~~~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:85:21 - error TS1109: Expression expected.
[ng] 85 to_json(options?: {
[ng] ~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:86:18 - error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.
[ng] 86 format?: "row" | "column";
[ng] ~~~~~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:86:26 - error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.
[ng] 86 format?: "row" | "column";
[ng] ~~~~~~~~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:86:34 - error TS1005: ',' expected.
[ng] 86 format?: "row" | "column";
[ng] ~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:87:20 - error TS2693: 'string' only refers to a type, but is being used as a value here.
[ng] 87 filePath?: string;
[ng] ~~~~~~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:87:26 - error TS1005: ',' expected.
[ng] 87 filePath?: string;
[ng] ~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:88:7 - error TS1005: ';' expected.
[ng] 88 }): object | void;
[ng] ~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:88:9 - error TS2304: Cannot find name 'object'.
[ng] 88 }): object | void;
[ng] ~~~~~~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:88:18 - error TS2532: Object
is possibly 'undefined'.
[ng] 88 }): object | void;
[ng] ~~~~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:88:22 - error TS1109: Expression expected.
[ng] 88 }): object | void;
[ng] ~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:89:5 - error TS2304: Cannot find name 'to_excel'.
[ng] 89 to_excel(options?: {
[ng] ~~~~~~~~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:89:14 - error TS2304: Cannot
find name 'options'.
[ng] 89 to_excel(options?: {
[ng] ~~~~~~~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:89:22 - error TS1109: Expression expected.
[ng] 89 to_excel(options?: {
[ng] ~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:90:20 - error TS2693: 'string' only refers to a type, but is being used as a value here.
[ng] 90 filePath?: string;
[ng] ~~~~~~
[ng] Error: 6mnode_modules/danfojs/types/shared/types.d.ts:90:26 - error TS1005: ',' expected.
[ng] 90 filePath?: string;
[ng] ~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:91:21 - error TS2693: 'string' only refers to a type, but is being used as a value here.
[ng] 91 sheetName?: string;
[ng] ~~~~~~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:91:27 - error TS1005: ',' expected.
[ng] 91 sheetName?: string;
[ng] ~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:92:7 - error TS1005: ';' expected.
[ng] 92 }): void;
[ng] ~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:92:13 - error TS1109: Expression expected.
[ng] 92 }): void;
[ng] ~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:93:12 - error TS1005: ';' expected.
[ng] 93 print(): void;
[ng] ~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:93:18 - error TS1109: Expression expected.
[ng] 93 print(): void;
[ng] ~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:94:1 - error TS1128: Declaration or statement expected.
[ng] 94 }
[ng] ~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:201:5 - error TS1131: Property or signature expected.
[ng] 201 get dtype(): string;
[ng] ~~~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:201:5 - error TS2304: Cannot
find name 'get'.
[ng] 201 get dtype(): string;
[ng] ~~~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:201:9 - error TS1005: ';' expected.
[ng] 201 get dtype(): string;
[ng] ~~~~~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:201:9 - error TS2304: Cannot
find name 'dtype'.
[ng] 201 get dtype(): string;
[ng] ~~~~~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:201:16 - error TS1005: ';' expected.
[ng] 201 get dtype(): string;
[ng] ~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:201:18 - error TS2693: 'string' only refers to a type, but is being used as a value here.
[ng] 201 get dtype(): string;
[ng] ~~~~~~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:202:5 - error TS2304: Cannot
find name 'drop_duplicates'.
[ng] 202 drop_duplicates(options?: {
[ng] ~~~~~~~~~~~~~~~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:202:21 - error TS2304: Cannot find name 'options'.
[ng] 202 drop_duplicates(options?: {
[ng] ~~~~~~~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:202:29 - error TS1109: Expression expected.
[ng] 202 drop_duplicates(options?: {
[ng] ~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:203:16 - error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.
[ng] 203 keep?: "first" | "last";
[ng] ~~~~~~~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:203:26 - error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or
an enum type.
[ng] 203 keep?: "first" | "last";
[ng] ~~~~~~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:203:32 - error TS1005: ',' expected.
[ng] 203 keep?: "first" | "last";
[ng] ~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:204:19 - error TS2693: 'boolean' only refers to a type, but is being used as a value here.
[ng] 204 inplace?: boolean;
[ng] ~~~~~~~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:204:26 - error TS1005: ',' expected.
[ng] 204 inplace?: boolean;
[ng] ~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:205:7 - error TS1005: ';' expected.
[ng] 205 }): Series | void;
[ng] ~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:205:9 - error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.
[ng] 205 }): Series | void;
[ng] ~~~~~~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:205:18 - error TS2532: Object is possibly 'undefined'.
[ng] 205 }): Series | void;
[ng] ~~~~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:205:22 - error TS1109: Expression expected.
[ng] 205 }): Series | void;
[ng] ~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:206:5 - error TS2304: Cannot
find name 'astype'.
[ng] 206 astype(dtype: "float32" | "int32" | "string" | "boolean", options?: {
[ng] ~~~~~~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:206:12 - error TS2304: Cannot find name 'dtype'.
[ng] 206 astype(dtype: "float32" | "int32" | "string" | "boolean", options?: {
[ng] ~~~~~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:206:17 - error TS1005: ',' expected.
[ng] 206 astype(dtype: "float32" | "int32" | "string" | "boolean", options?: {
[ng] ~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:206:19 - error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.
[ng] 206 astype(dtype: "float32" | "int32" | "string" | "boolean", options?: {
[ng] ~~~~~~~~~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:206:31 - error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or
an enum type.
[ng] 206 astype(dtype: "float32" | "int32" | "string" | "boolean", options?: {
[ng] ~~~~~~~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:206:41 - error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or
an enum type.
[ng] 206 astype(dtype: "float32" | "int32" | "string" | "boolean", options?: {
[ng] ~~~~~~~~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:206:52 - error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or
an enum type.
[ng] 206 astype(dtype: "float32" | "int32" | "string" | "boolean", options?: {
[ng] ~~~~~~~~~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:206:63 - error TS2304: Cannot find name 'options'.
[ng] 206 astype(dtype: "float32" | "int32" | "string" | "boolean", options?: {
[ng] ~~~~~~~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:206:71 - error TS1109: Expression expected.
[ng] 206 astype(dtype: "float32" | "int32" | "string" | "boolean", options?: {
[ng] ~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:207:19 - error TS2693: 'boolean' only refers to a type, but is being used as a value here.
[ng] 207 inplace?: boolean;
[ng] ~~~~~~~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:207:26 - error TS1005: ',' expected.
[ng] 207 inplace?: boolean;
[ng] ~
[ng] Error: node_modules/danfojs/types/shared/types.d.ts:208:7 - error TS1005: ';' expected.
[ng] 208 }): Series | void;
【问题讨论】:
-
您还必须安装
@tensorflow/tfjs-node。检查这里,danfo.jsdata.org/getting-started#creating-a-dataframe-series -
即使安装了
@tensorflow/tfjs-node,问题仍然存在。 -
很抱歉,我找不到任何说明我需要安装
@tensorflow/tfjs-node的参考资料(在您提供的链接中)。 @Piyush 耆那教
标签: javascript angular typescript tensorflow danfojs