Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This module should not be used in runtime. Instead, use a transformer during compilation. #14

Closed
jtremback opened this issue Mar 3, 2019 · 10 comments

Comments

@jtremback
Copy link

I just wanted to drop this in here for your information. I don't know the root cause, or whether this issue even belongs in this repo but I thought it might be helpful for you to know about this.

When running with ts-node-dev --compiler ttypescript --respawn --transpileOnly src/index.ts, I get the error This module should not be used in runtime. Instead, use a transformer during compilation. when the validator runs. I don't get the error in parts of the program where the validator is not running.

Removing the --transpileOnly fixes the problem.

@woutervh-
Copy link
Owner

hi @jtremback

The error you mentioned only happens when the transformer from typescript-is is not used. The default implementation is to throw a run-time error.
I'm not exactly sure why the transformer is not used, but as you mentioned that removing the --transpileOnly flag resolved the issue, I'm guessing that this option causes ts-node-dev to skip the transformation part.
Digging a bit further into ts-node-dev this option sounds like it causes the compiler to strip out the type checking part and just emit JS code. That would definitely prevent typescript-is from transforming the code and generating type guards, because it needs the type information to do this.

I hope this clarifies the situation. There is not much I can do if the entire type checking part of compilation is skipped.

Is there anything else you'd like to have clarified?

Thanks!

@woutervh-
Copy link
Owner

Closing for housekeeping purposes.

@jtremback
Copy link
Author

Thanks @woutervh- !

@mtiller
Copy link

mtiller commented May 13, 2019

I got this same error when trying to run jest tests. I added the plugins section to my tsconfig.json, but perhaps ts-jest is somehow overriding those settings?!?

@woutervh-
Copy link
Owner

Hi @mtiller

I'm not sure how ts-jest runs the compiler. Sounds like there should be some configuration in ts-jest to enable ttypescript or vice versa. Maybe there is some info on these two repos about how to do it.

@mtiller
Copy link

mtiller commented Oct 30, 2019

I ran into this issue again. I found that if I added:

globals: {
    "ts-jest": {
      compiler: "ttypescript"
    }
  }

...to my jest.config.js file, the issue went away.

@yanshiyason
Copy link

@mtiller Thank you for sharing!!

@bergkvist
Copy link

I'm still getting this error running npm start

Error: This module should not be used in runtime. Instead, use a transformer during compilation.

My package.json:

{
  "scripts": {
     "start": "ts-node-dev --compiler ttypescript --respawn src/index.ts"
  },
  "dependencies": {
    "typescript": "^3.8.3"
  },
  "devDependencies": {
    "ts-node-dev": "^1.0.0-pre.44",
    "ttypescript": "^1.5.10",
    "typescript-is": "^0.15.0"
  }
}

My tsconfig.json:

{
  "compilerOptions": {
    "plugins": [
      { "transform": "typescript-is/lib/transform-inline/transformer" }
    ],
    "target": "es5",
    "module": "commonjs",
    "strict": true,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true
  }
}

@nevillco
Copy link

nevillco commented Apr 24, 2021

I'm also seeing this error message on a new Node project. The verbose flag confirms the plugin is running (I get typescript-is: transforming program with 287 source files; using TypeScript 4.2.4.), but then still receive This module should not be used in runtime. Instead, use a transformer during compilation at runtime. Not sure if I'm missing something or something is broken.

I've tried npx ttsc, ts-node-dev --compiler typescript, and both of those as my npm run build command; in both cases I get the same result (verbose message that the files are being transformed but a "Module should not be used at runtime" error.

package.json:

{
  "scripts": {
    "lint": "eslint . --ext .ts",
    "build": "npm run lint && npx ttsc",
    "serve": " firebase use develop && npm run build && firebase emulators:start --only auth,functions,firestore",
    "deploy": "firebase deploy --only functions",
    "test": "env TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' mocha -r ts-node/register 'test/tests/**/*.ts'"
  },
  "engines": {
    "node": "12"
  },
  "main": "lib/index.js",
  "dependencies": {
    ...
    "reflect-metadata": "^0.1.13",
    "typescript-is": "^0.18.2"
  },
  "devDependencies": {
    ...
    "ts-node": "^9.1.1",
    "ts-node-dev": "^1.1.6",
    "ttypescript": "^1.5.12",
    "typescript": "^4.2.4"
  },
  "private": true
}

tsconfig.json:

{
  "compilerOptions": {
    "baseUrl": "./src",
    "module": "commonjs",
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "allowJs": false,
    "outDir": "lib",
    "sourceMap": true,
    "strict": true,
    "target": "es2017",
    "forceConsistentCasingInFileNames": true,
    "plugins": [
      {
        "transform": "typescript-is/lib/transform-inline/transformer",
        "verbose": true,
      },
    ]
  },
  "include": [
    "src/**/*",
  ],
  "compileOnSave": true,
}

@francescov1
Copy link

Any solution for this? Still running into it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants