TypeScript找不到包含附带的.d.ts类型的npm模块(带有ts-loader的webpack)

时间:2019-02-17 08:59:23

标签: typescript npm webpack typescript-typings konvajs

我正在尝试将Konva库导入到我的TypeScript + webpack项目中,但是编译器无法在不直接将其指向.d.ts的情况下找到该模块。

没有适用于Konva的DefinitelyTyped程序包,.d.ts文件已包含在npm程序包中。我可以导入{em>确实以我期望的方式具有DefinitelyTyped条目的another npm软件包。

我尝试将resolve.extentions添加到webpack.config.js中的node_modules/ '-- @types/ '-- tesseract.js/ '-- index.d.ts '-- package.json '-- types-metadata.json '-- konva/ '-- src/ '-- konva.d.ts '-- konva.js '-- konva.min.js '-- package.json '-- tesseract.js/ '-- dist/ '-- src/ '-- package.json src/ '-- index.ts package.json package-lock.json tsconfig.json webpack.config.js 中,但这也无济于事。我在他们的these上发现了issues github,但都被标记为已关闭。

目录结构

types-metadata.json

我能找到的唯一显着区别是Konva没有import * as Konva from 'konva' //this errors import * as Tesseract from 'tesseract.js'; //this works fine //import * as Konva from '../node_modules/konva/konva' this 'works' too ... 文件。这可能是问题吗?我在此文件上找不到任何文档。

index.ts

const path = require('path');

module.exports = {
    entry: './src/index.ts',
    devtool: 'source-map',

    output: {
        filename: 'main.js',
        path: path.resolve(__dirname, 'dist'),
    },

    resolve: {
        extensions: [ '.ts', '.tsx', '.js']
    },

    module: {
        rules: [
            { test: /\.ts$/, use: 'ts-loader' },
        ]
    },
    ...
};

webpack.config.js

{
    ...
    "devDependencies": {
        "ts-loader": "^5.3.3",
        "typescript": "^3.3.3",
        "webpack": "^4.29.4",
        "webpack-cli": "^3.2.3"
    },
    "dependencies": {
        "@types/tesseract.js": "0.0.2", //this library is working perfectly
        "tesseract.js": "^1.0.14"
        "konva": "^2.6.0", //this one isn't
    }
    ...
}

package.json

{
    "compileOnSave": true,

    "compilerOptions": {
        "target": "es2016",
        "sourceMap": true,

        "strict": true,
        "alwaysStrict": true,
        "strictNullChecks": true,
        "strictFunctionTypes": true,
        "strictBindCallApply": true,
        "strictPropertyInitialization": true,

        "noImplicitAny": true,
        "noImplicitThis": true,
        "noImplicitReturns": true,
        "noFallthroughCasesInSwitch": true,

        "forceConsistentCasingInFileNames": true,
    }
}

tsconfig.json

$pdr = Panier::find($pn);

0 个答案:

没有答案