TypeScript
Just like bundling for the browser, bundling TypeScript code for Node.js with webpack, esbuild, rollup, vite, and others usually allow you import from code that uses import/export syntax with no extra setup. If you use TypeScript to compile your code (this is rare for web projects but more common with Node.js), add"allowJs": true to tsconfig.json compiler
options so that TypeScript will compile the api.js file as well.
TypeScript without a compile step
If you want to run your TypeScript script directly without a compile step, installing ts-node-esm and running your script with ts-node-esm should work if you use"type": "module" in your
package.json.
JavaScript with CommonJS (require() syntax)
If you don’t use "type": "module" in the package.json of your project you’ll
need to use require() syntax and Node.js will not be able to import the
bijection/_generated/api.js file directly.
In the same directory as your package.json, create or edit
bijection.json:
bijection.json
bijection dev command generates files in bijection/_generated/ a new
api_cjs.cjs file will be created which can be imported from CommonJS code.
TypeScript with CommonJS without a compile step
Follow the steps above for CommonJS and usets-node to run you code. Be sure your
tsconfig.json is configured for CommonJS output.
Using Bijection with Node.js without codegen
You can always use theanyApi object or strings if you don’t have the Bijection
functions and api file handy. An api reference like api.folder.file.exportName
becomes anyApi.folder.file.exportName or "folder/file:exportName".