node.jstypescriptmodule

import module for side-effects with Typescript only targeting node


GIVEN:

A ts module with an import but no export calls named ./snippets.ts
A ts module called ./main.ts
A tsconfig as follows...

{
  "compilerOptions": {
    "target": "ESNext",                          
    "module": "commonjs",                     
    "allowJs": true,                       
    "checkJs": true,                       
    "sourceMap": true,                     
    "downlevelIteration": true,            
    "noImplicitAny": true,                 
    "moduleResolution": "node",            
    "allowSyntheticDefaultImports": true,  
    "esModuleInterop": true,                   
    "baseUrl": ".",
  },
  "exclude": [
    "node_modules"
  ]
}

Question:

How do I import the ./snippets file in the ./main module so as I can be assured that ./snippets has run before ./main?

I have tried import from "./snippet"; and import * as arbitrarySymbol from "./snippet"; and variations with no success.


Solution

  • import "./snippet";
    

    should do the trick as described here