首页 > 解决方案 > ca.select(...).from 不是缩小后的函数

问题描述

在我的Angular应用程序中,我使用的是squel.js,并且在开发模式下使用时效果很好。

但是,当我为生产构建应用程序并尝试使用它时,出现以下错误:

ca.select(...).from 不是函数

在非缩小代码中对应于:

import * as squel from 'squel';

// ...

squel.select().from(...)

标签: angulartypescriptangular-climinifysquel.js

解决方案


该问题是由squel.js中的一个错误引起的,该错误会在缩小后阻止使用它。

解决方案(解决方法)

1) 包括 sqlite 作为脚本,angular.json而不是import通过将其添加到scripts数组中来使用projects.myAppName.architect.build.options

"scripts": [
  "node_modules/squel/dist/squel.min.js"
]

projects.myAppName.architect.test.options为了修复单元测试也做同样的事情。


2) 现在生产包很好,但我们必须修复类型,以便 ts 编译器也可以工作。

由于我们删除了:

import * as squel from 'squel';

喜欢的所有类型squel.Insert都会被破坏。

我们需要添加:

declare const squel: Squel & {flavour: null};

现在所有类型如squel.Insert, squel.Delete, etc... 将被Insert, Delete, etc... 替换,当然我们需要导入它们:

import { Squel, Delete, Insert } from 'squel';

这种方式我们import只用来导入类型定义而不是整个库。

例子

https://github.com/azerothcore/Keira3/commit/98f191eb59cf9c853dd8a54a845a029c7a4ddef8


推荐阅读