digitsensitive / astar-typescript

A* search algorithm in TypeScript
MIT License
87 stars 18 forks source link

Unable to use library in typescript project complied with rollup #23

Closed veleek closed 3 years ago

veleek commented 3 years ago

I'm importing the package into a typescript project that's compiled with rollup. Unfortunately, when I try to build with this referenced (import { AStarFinder } from "astar-typescript";) rollup fails with the error:

Error: 'AStarFinder' is not exported by node_modules\astar-typescript\dist\astar.js, imported by game.ts

I've fiddled around with various plugin changes and options for plugin-commonjs (stuff like adding it to the includes list to force it to be parsed as a CommonJS module but nothing seems to work. Can someone help me figure out the incantation to get this working with rollup?

This is more of a rollup question I suppose, but if you have any thoughts or ideas around ways to get it working that would be great!

digitsensitive commented 3 years ago

Please be sure, that your configuration files are correct. Have a look at the example folders.

veleek commented 3 years ago

Yeah, everything appears to be correct. I think it's probably more of a specific rollup issue, was just hoping maybe you had some insight into how it should work.

veleek commented 3 years ago

In case anybody else running into this problem, I'm hoping it'll be answered by this Stack Overflow thread.

agaAdams commented 2 years ago

You have to tell the 'rollup-commonjs-plugin' to convert your imported library's modules into a format Rollup can use:

In your rollup config edit the part concerning the commonjs-plugin:

commonjs({
    include: [
        'node_modules/eventemitter3/**',
        'node_modules/phaser/**',
        'node_modules/astar-typescript/**',
        'node_modules/lodash/**',
    ],
    exclude: [ 
        'node_modules/phaser/src/polyfills/requestAnimationFrame.js',
    ],
    sourceMap: true,
}),