I'm using TSDX to create my module, which implements rollup, and I'm running into an issue with using the module correctly in another project. The module seems to build and publish just fine, I'm able to install it in my other project, and I'm getting no errors in my code, but once I open it in browser, I get this error:
Uncaught TypeError: Failed to resolve module specifier. Relative references must start with either "/", "./", or "../".
I'm not sure why it's trying to treat them as relative references when they are from a module, and I'm wondering if it has to do with my directory structure or how rollup is bundling everything together. My directory structure in the module itself is as follows:
src
generics
class1.ts
class2.ts
class3.ts
globals
plugins
plugin1.ts
plugin2.ts
class4.ts
type1.ts
interface1.ts
index.ts
.gitignore
.npmignore
.npmrc
package-lock.json
package.json
tsconfig.json
Using npm run build
creates a distribution folder with the following structure, which is then published using GitHub Packages:
dist
generics
class1.d.ts
class2.d.ts
class3.d.ts
globals
plugins
plugin1.d.ts
plugin2.d.ts
class4.d.ts
type1.d.ts
interface1.d.ts
module-name.cjs.development.js
module-name.cjs.development.js.map
module-name.cjs.production.min.js
module-name.cjs.production.min.js.map
module-name.esm.js
module-name.esm.js.map
index.d.ts
index.js
Here are my import statements:
import {Class} from 'module-name/dist/index.d.js';
import {Plugin1} from 'module-name/dist/globals/plugins/plugin1.d.js'
import {Plugin2} from 'module-name/dist/globals/plugins/plugin2.d.js'
What causes this error, and how can I avoid it? Am I exporting/importing the classes from my module incorrectly? Please let me know if you need additional information, I wasn't quite sure what to provide