Comments (10)
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.
from typescript-is.
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
}
}
from typescript-is.
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,
}
from typescript-is.
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!
from typescript-is.
Closing for housekeeping purposes.
from typescript-is.
Thanks @woutervh- !
from typescript-is.
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?!?
from typescript-is.
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.
from typescript-is.
@mtiller Thank you for sharing!!
from typescript-is.
Any solution for this? Still running into it
from typescript-is.
Related Issues (20)
- Feature Request: Shortcut to simplify `const v = func(); is<type>(v) ? v : default` HOT 1
- Fix intersections with primitives to add support for branded/flavored types HOT 1
- Intersection disables `disallowSuperfluousProperties` all the way down
- Non-deterministic code generated HOT 1
- Support typeof on object types
- Parsing fails when target & aliasTypeArguments are at different levels HOT 1
- Investigation of Unbound Type Parameters
- typescript-is introduces "typescript" dependency into production environment
- TypeError: Cannot read property 'text' of undefined
- Bug: A missing key and a key with a value of undefined are not considered the same
- Fail to check Enum in Record HOT 9
- Have you plan to support Deno? HOT 2
- use instantiation expressions in typescript 4.7
- Make generated code smaller by putting reusable strings to constants or functions HOT 1
- feature request: set custom error class in AssertType
- Thoughts on extending createAssertType() HOT 1
- Incompatible with TypeScript 4.8 HOT 2
- What about re-export `typia` for maintenance? HOT 1
- ttypescript not support TS@5
- Deprecation message and recommends to use `typia` instead HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typescript-is.