Server runtime - rollup not resolving imports from @types/node

Hello :slight_smile:

I am trying to set up a Typescript server runtime using rollup, as described in the docs. my rollup config looks exactly like the one from the docs.

I am installing a library called jimp for image manipulation. Rollup seems to bundle most of jimp just fine, except for the dependencies on @types/node. See the first few lines of my transpiled index.js, which include several import statements:

import fs$4, { mkdir, stat as stat$1, statSync, mkdirSync } from 'fs';
import Path, { dirname, resolve, parse as parse$1 } from 'path';
import EventEmitter from 'events';
import Stream$3 from 'stream';
import http$1 from 'http';
import Url from 'url';
import require$$0$1 from 'punycode';
import https$1 from 'https';
import zlib$5 from 'zlib';
import require$$0$2 from 'util';
import require$$0$3 from 'assert';
import require$$3 from 'buffer';
import require$$3$1 from 'querystring';
import require$$1$1 from 'string_decoder';
import require$$4 from 'timers';

It seems that what these imports have in common is they are all from node_modules/@types/node.
To be clear, these import statements break my runtime in docker.

SyntaxError: index.js: Line 1:1 Unexpected reserved word

Hey @seltzerfish our Typescript runtime isn’t a NodeJS runtime.

Ahh i see. So does that mean it’s impossible to use npm libraries that rely on NodeJS, like Jimp? Do you have any other suggestions on how I might achieve server-side image manipulation?

That’s correct. I personally would not write image manipulation code in Typescript. You should write it in Go. It somewhat depends though on what you are trying to do with the images.