Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Webpack Typescript,Web包:未捕获的TypeError:对象(…)不是函数_Webpack_Import_Typeerror - Fatal编程技术网

Webpack Typescript,Web包:未捕获的TypeError:对象(…)不是函数

Webpack Typescript,Web包:未捕获的TypeError:对象(…)不是函数,webpack,import,typeerror,Webpack,Import,Typeerror,我使用Typescript创建了自己的函数库。此库的一个组件是Aircraft.ts,它导出以下功能: export function SimulateAircraft(dt: number, s0: IAircraftState, phi_cmd: number): IAircraftState 然后使用Webpack、ts加载器和dts捆绑包将它们打包成单个.js文件和单个.d.ts文件index.ts只需重新导入所有组件: export * from './components/Airc

我使用Typescript创建了自己的函数库。此库的一个组件是Aircraft.ts,它导出以下功能:

export function SimulateAircraft(dt: number, s0: IAircraftState, phi_cmd: number): IAircraftState
然后使用Webpack、ts加载器和dts捆绑包将它们打包成单个.js文件和单个.d.ts文件index.ts只需重新导入所有组件:

export * from './components/Aircraft'
该库未部署到npm,但我已使用
npm link
在本地开发环境中提供了它

然后,我将函数从库导入到另一个Typescript项目中

import { IAircraftState, SimulateAircraft } from 'oset';
其中,我使用的函数如下所示:

setInterval(() => {
      const ac = SimulateAircraft(0.1, this.state.ac, 0);
      this.setState({ ac });
    }, 100);
项目生成时没有任何错误。VSCode也不会显示任何错误,intellisense也会正确显示导入的函数定义。 但是,在运行时,我在浏览器控制台中遇到以下错误:

Uncaught TypeError: Object(...) is not a function
错误所指的对象是
SimulateAircraft
,该对象似乎未定义。我已经寻找了相当长的时间,试图找到一个解决办法。我发现了类似的错误及其解决方法,但我还没有找到解决问题的方法。我真的很感谢你的帮助

webpack.config.js

package.json

{
“名称”:“oset”,
“版本”:“0.0.0”,
“说明”:“…”,
“main”:“/dist/index.js”,
“类型”:“/dist/index.d.ts”,
“脚本”:{
“构建”:“网页包”,
“清洁”:“rm-rf距离”,
“覆盖范围”:“npm测试——覆盖范围”,
“测试”:“开玩笑——看”
},
“存储库”:{
“类型”:“git”,
“url”:“…”
},
“依赖性”:{
“@types/jest”:“^23.3.1”,
“dts捆绑包”:“^0.7.3”,
“玩笑”:“^23.5.0”,
“ts笑话”:“^23.1.4”,
“类型脚本”:“^3.0.3”
},
“依赖项”:{
“redux”:“^4.0.0”
},
“笑话”:{
“测试环境”:“节点”,
“CollectionCoverage from”:[
“/src/*/**.{ts,tsx}”
],
“转变”:{
“^.+\.tsx?$”:“ts笑话”
},
“testRegex”:“(/\uuuuu tests./**)(\\.\.\.\.\./)(test | spec))\\\\.(jsx?;tsx?)$”,
“moduleFileExtensions”:[
“ts”,
“tsx”,
“js”,
“jsx”,
“json”,
“节点”
],
“详细”:正确,
“testURL”:”http://localhost/"
}
}

可能太晚了,但请尝试:

import * as aircraft from 'oset';
然后:

setInterval(() => {
      const ac = aircraft.SimulateAircraft(0.1, this.state.ac, 0);
      this.setState({ ac });
    }, 100);

请共享您的网页包和jsonok包。我把它们添加到原来的问题中。
import * as aircraft from 'oset';
setInterval(() => {
      const ac = aircraft.SimulateAircraft(0.1, this.state.ac, 0);
      this.setState({ ac });
    }, 100);