У меня есть задача gulp, которая запускает накопительный пакет, компилирует машинопись и генерирует модули для динамического импорта:
const rollup = require('rollup');
const rolltypescript = require('rollup-plugin-typescript');
const babel = require('rollup-plugin-babel');
const resolve = require('rollup-plugin-node-resolve');
const commonjs = require('rollup-plugin-commonjs');
const omt = require('@surma/rollup-plugin-off-main-thread');
function typescript() {
return rollup.rollup({
input: 'app/scripts/main.ts',
plugins: [
omt(),
rolltypescript(),
resolve(),
commonjs(),
babel({
babelrc: false,
presets: [['@babel/preset-env', { modules: false }]],
plugins: ['@babel/plugin-syntax-dynamic-import']
})
]
}).then(bundle => {
return bundle.write({
dir: '.tmp/scripts/output',
format: 'amd',
name: 'library',
sourcemap: true
}).then(() => {
return src('.tmp/scripts/output/main.js') // I did this because the path output was wrong. See: https://github.com/rollup/rollup/issues/2463
.pipe($.replace(/require\(\['\.\//g, `require(['./scripts/output/`))
.pipe(dest('.tmp/scripts'))
.pipe(server.reload({ stream: true }));
});
});
};
эта задача генерирует все файлы правильно, но я получаю в консоли браузера ошибку
main.js:36 Uncaught (in promise) Error: Module ./scripts/output/file-0d52c3ae.js didn’t register its module
at singleRequire (main.js:36)
at async Promise.all (:9000/index 0)
at async require (main.js:43)
Я не уверен, что мне следует делать сейчас, чтобы исправить ошибку.