我正在开发一个库,在我开始做单元测试之前,这个库一直运行良好。直到几天前,我可以通过以下方式实例化我的库。
this.belpay = new belpay.SDK('test', {
username: 'username',
password: 'password',
key: 'abc-def',
});
在我的chrome控制台里
现在我出现了以下错误:
为了消除这个错误,我不得不做了下面的工作。
this.belpay = new belpay.default('test', {
username: 'username',
password: 'password',
key: 'abc-def',
});
我不明白为什么现在会显示为默认值 I don't understand why now it shows me default. 我在rollup.config.js中一直有这个设置。
import nodePolyfills from 'rollup-plugin-node-polyfills';
import babel from 'rollup-plugin-babel';
import serve from 'rollup-plugin-serve';
import commonjs from '@rollup/plugin-commonjs';
import livereload from 'rollup-plugin-livereload';
import { terser } from 'rollup-plugin-terser';
import json from 'rollup-plugin-json';
export default {
input: 'src/index.js',
context: 'window',
output: [
{
file: 'dist/belpay.js',
format: 'umd',
name: 'belpay',
exports: 'named',
globals: ['axios'],
},
{
file: 'dist/belpay.min.js',
format: 'umd',
name: 'belpay',
plugins: [terser()],
exports: 'named',
},
],
external: ['axios'],
plugins: [
babel({
exclude: ['node_modules/**'],
runtimeHelpers: true,
}),
nodePolyfills(),
serve({
host: 'localhost',
port: 1234,
contentBase: 'dist',
historyApiFallback: true,
allowCrossOrigin: true,
}),
commonjs({
include: 'node_modules/axios/**',
}),
livereload({
watch: 'dist',
verbose: true,
}),
json(),
],
};
(编辑)
我的entryfile(srcindex.js)的内容。
export default class SDK {
#myvar= '';
#myobject = {};
method1() {}
method2() {}
}
这样一来,我就把库导入了。distindex.html
<!-- html content -->
...
<!-- at the end of the body tag. -->
<script type="module" src="./belpay.js"></script>
<script type="text/javascript">
this.belpay = new belpay.SDK();
</script>
这很奇怪,因为在周五(本周最后一个工作日),我让它工作得很好,但在周一我不能再做测试。我没有做任何改动。
任何改善这个文件的建议都会受到欢迎。
我发现了问题所在。我当时正在做。
export default class SDK {}
不得不这么做。
export class SDK {}
我没有设置 "默认"。