I'm developing a fairly straight forward typescript node app and I wanted to include this library correct-frequency-random-letters. I figured I could just get by using just tsc and running the output with node. However, with stock compiler and "module" set to "commonjs" for my tsconfig, I get this error:
C:\Users\gabek\code\gamejay-bot\node_modules\correct-frequency-random-letters\dist\index.js:16
import FrequencyType from "./frequency/FrequencyType";
^^^^^^
SyntaxError: Cannot use import statement outside a module
at Object.compileFunction (node:vm:352:18)
at wrapSafe (node:internal/modules/cjs/loader:1026:15)
at Module._compile (node:internal/modules/cjs/loader:1061:27)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1149:10)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:999:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (C:\Users\gabek\code\gamejay-bot\dist\word-hunt\main.js:4:44)
at Module._compile (node:internal/modules/cjs/loader:1097:14)
Node.js v17.3.0
As you can see, it's being thrown in the package itself, so I can't futz around with .cjs vs .js file extensions. This means solutions like changing my node project type to "module" or changing my "module" setting to "esnext" in tsconfig seems to just make things worse (in the latter option, it breaks all my imports in the code I've actually written. I'm actually not sure why, but I get this error on all my imports: Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?
)
I feel like I haven't done anything particularly complicated here. Am I missing something? How would someone do this properly? I even tried using a bundler like Rollup but I ended up with the exact same error and a bunch of other more complicated Rollup-specific solutions to try... but I figured before I went that route I'd ask here.