question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Vue Typescript starter - import.meta.env unusuable

See original GitHub issue

Hey currently you cannot use Vite’s enviroment variables with the Vue typescript starter because the the tsconfig module option is set to “CommonJS”.

tsconfig.json
{
  "compilerOptions": {
    "strict": true,
    "module": "CommonJS",
    "target": "ES2020",
    "lib": ["DOM"],
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "baseUrl": "./",
    "paths": {
      "~/*": ["./src/*"]
    },
  },
  "ts-node": {
    "transpileOnly": true
  }
}
Screenshot 2021-06-17 at 14 50 55

Is there a way around this?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:21 (15 by maintainers)

github_iconTop GitHub Comments

1reaction
brilloutcommented, Jul 19, 2021

Hm, seems like a bug in ts-node. But yea you’ll eventually find the problem by further digging 😃

On Mon, Jul 19, 2021 at 2:32 PM Stephen Samra @.***> wrote:

@brillout https://github.com/brillout, you were right that ts-node was not picking up the tsconfig.json#ts-node options.

Adding a console.log inside ts-node for those options showed:

{ “transpileOnly”: undefined, “compilerOptions”: undefined}

However, when I inline those options in the package.json script like so:

“scripts”: { “dev”: “ts-node --transpile-only --compiler-options ‘{"module":"CommonJS"}’ ./server”, }

… it shows:

{ “transpileOnly”: true, “compilerOptions”: { “module”: “CommonJS” }}

Unfortunately, even with those options set, I still get the same error so I’m still looking into it. Thanks for the help thus far though!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/brillout/vite-plugin-ssr/issues/101#issuecomment-882509794, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHVQRWCCFFMUWFQJD7NTOLTYQLNVANCNFSM463XKSXQ .

1reaction
brilloutcommented, Jul 19, 2021

@deckchairlabs That is correct. In particular import.meta doesn’t exist in server.js. But better to have false positive than not being able to use import.meta at all.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript Types for import.meta.env - vue.js - Stack Overflow
I am now using a framework (vite) that injects environment variables into import.meta.env .
Read more >
Env Variables and Modes - Vite
Vite exposes env variables on the special import.meta.env object. ... It will also replace these strings appearing in JavaScript strings and Vue templates....
Read more >
[Solved]-Typescript Types for import.meta.env-Vue.js
ts should be placed in your src/ directory and you need a reference string at the top of the file. A complete, working...
Read more >
Introducing Import-meta-env - Simple but strict solution to use ...
There are some questions I answered related to the problem this package is trying to solve: Pass environment variable into a Vue App...
Read more >
Vue.js: Environment-Aware Code in TypeScript - Peter's
I ran into the situation that a certain single-page application was developed separately from the backend, which really isn't so unusual for ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found