Twine Version: 2.3.x
Story Format: Sugarcube 2.35
I’ve been doodling along with Twine+Sugarcube, learning and modifying and having a ball. I wanted to add an npm package to the mix, so I did a classic “npm -i moduleName --save” and all looks fine. I use “import suchAndSuch from soAndSo”, no problem. But when I load the resulting game code in the browser, I get “Cannot use import outside of a module”. I tried changing the type of the app.js import directly (a hack!) in the HTML file to module but that just threw more errors (the original type is “text/twine-javascript”, so yeah, probably not suppose to change that). I have a feeling I’m just doing this wrong. Not even sure this is a Twine question as such, more likely I’ve screwed up my compilation setup.
To be clear, I’m actually coding in Typescript, and compiling that into ES6. The package I was trying to import was spotlight.js (for showing images).
package.json (excerpted)
"type": "module",
"browserslist": [
"defaults"
],
"devDependencies": {
"@types/jquery": "^3.5.8",
"sass": "^1.43.4"
},
"private": true,
"dependencies": {
"@types/twine-sugarcube": "^2.34.2",
"spotlight.js": "^0.7.8"
}
tsconfig.json
{
"include": ["src/ts/**/*"],
"compilerOptions": {
"strict": false,
"target": "ES2015",
"sourceMap": true,
"outDir": "src/js",
"lib": [
"dom",
"ES2015"
],
"module": "ES2015",
"moduleResolution": "Node",
}
}