javascript 如何修复TypeError:ExtPay不是Typscript和Webpack Bundle的函数

qvtsj1bj  于 2023-06-04  发布在  Java
关注(0)|答案(1)|浏览(141)

我试图安装ExtPay支付库的Chrome扩展作为链接https://github.com/Glench/ExtPay,我按照指示,直到3.Add ExtPay到background.js,然后我得到了错误,我想,因为我使用的Typescript和Webpack这样
background.ts

import "ExtPay"
const extpay = ExtPay("sample-extension")

错误TS2552:找不到名称“ExtPay”。你说的是“下一次付款”吗
评论I Try

const ExtPay = require("ExtPay")
const extpay = ExtPay("sample-extension")

发现错误TypeError:ExtPay不是一个函数
有什么想法?
这是我的webpack配置
webpack.common.js

const CopyPlugin = require('copy-webpack-plugin');
const HtmlPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');

module.exports = {
entry: {
popup: path.resolve('src/popup/popup.tsx'),
options: path.resolve('src/options/options.tsx'),
background: path.resolve('src/background/background.ts'),
contentScript: path.resolve('src/contentScript/contentScript.ts'),
context: path.resolve('src/contentScript/context.ts'),
},
module: {
rules: [
{
test: /.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
{
test: /.css$/i,
use: ['style-loader', 'css-loader'],
},
{
test: /.(jpg|jpeg|png|woff|woff2|eot|ttf|svg)$/,
type: 'asset/resource'
}
]
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
plugins: [
new CleanWebpackPlugin({
cleanStaleWebpackAssets: false,
}),
new CopyPlugin({
patterns: [
{
from: path.resolve('src/static'),
to: path.resolve('dist'),
}
]
}),
...getHtmlPlugins([
'popup',
'options'
]),
],
output: {
filename: '[name].js',
path: path.resolve('dist'),
},
optimization: {
splitChunks: {
chunks(chunk) {
return chunk.name !== 'contentScript' && chunk.name !== 'background' && chunk.name != 'context'
}
},
}
}

function getHtmlPlugins(chunks) {
return chunks.map(chunk => new HtmlPlugin({
title: 'React Extension',
filename: ${chunk}.html,
chunks: [chunk],
}))
}

Webpack.dev.js

const { merge } = require('webpack-merge');
const common = require('./webpack.common.js');

module.exports = merge(common, {
mode: 'development',
devtool: 'cheap-module-source-map',
})
f8rj6qna

f8rj6qna1#

这在我开发一个webpack项目时很有效(我还没有部署到最后)。

const ep = require('extpay');
ep.default('extension-name-in-extpay-config');

例如,沿着这条线的某处,初始化函数已经被向下推一级到模块的“默认”对象,不管它是什么。

相关问题