chihab / dotenv-run

Seamlessly load environment variables. Supports cli, esbuild, rollup, vite, webpack, angular. ESM and Monorepos.
246 stars 17 forks source link

Property 'env' does not exist on type 'ImportMeta'. #46

Closed HuserOz closed 10 months ago

HuserOz commented 1 year ago

interface ImportMetaEnv { /**

But when i try to read the NG_APP_VERSION in my environment.ts file like this:

export const environment = {
  production: false,
  version: import.meta.env.NG_APP_VERSION,
};

i'm getting this error:

./src/environments/environment.ts - Error: Module parse failed: parser.destructuringAssignmentPropertiesFor is not a function
File was processed with these loaders:
 * ./node_modules/@angular-devkit/build-angular/src/babel/webpack-loader.js
 * ./node_modules/@ngtools/webpack/src/ivy/index.js
You may need an additional loader to handle the result of these loaders.
TypeError: parser.destructuringAssignmentPropertiesFor is not a function

Error: src/environments/environment.ts:7:24 - error TS2339: Property 'env' does not exist on type 'ImportMeta'.

I can see that builders are changed to ngx-env builders in my angular.json file:

"serve": {
  "builder": "@ngx-env/builder:dev-server",
  "options": {
    "browserTarget": "prtime:build"
  },
  "configurations": {
    "production": {
      "browserTarget": "prtime:build:production"
    }
  }
},

What might be causing this error?

chihab commented 1 year ago

Could you please provide the output of this command in your CLI workspace?

npm list webpack @angular/core @ngx-env/builder
HuserOz commented 1 year ago
Screenshot 2023-06-12 113715
sme-tuga001 commented 1 year ago

I think it depends on the settings or typescript version /// <reference path="../env.d.ts" /> for env files should fix this error

menosprezzi commented 1 year ago

Same issue here! At. Node 16.20 and Angular 15.2

Also happens with @ngx-env/builder@16

├─┬ @angular-devkit/build-angular@15.2.9
│ ├─┬ @angular-devkit/build-webpack@0.1502.9
│ │ ├─┬ webpack-dev-server@4.15.1
│ │ │ ├─┬ webpack-dev-middleware@5.3.3
│ │ │ │ └── webpack@5.86.0 deduped
│ │ │ └── webpack@5.86.0 deduped
│ │ └── webpack@5.86.0 deduped
│ ├─┬ @angular/service-worker@15.2.9
│ │ └── @angular/core@15.2.9 deduped
│ ├─┬ @ngtools/webpack@15.2.9
│ │ └── webpack@5.86.0 deduped
│ ├─┬ babel-loader@9.1.2
│ │ └── webpack@5.86.0 deduped
│ ├─┬ copy-webpack-plugin@11.0.0
│ │ └── webpack@5.76.1 deduped
│ ├─┬ css-loader@6.7.3
│ │ └── webpack@5.76.1 deduped
│ ├─┬ less-loader@11.1.0
│ │ └── webpack@5.86.0 deduped
│ ├─┬ mini-css-extract-plugin@2.7.2
│ │ └── webpack@5.76.1 deduped
│ ├─┬ postcss-loader@7.0.2
│ │ └── webpack@5.76.1 deduped
│ ├─┬ sass-loader@13.2.0
│ │ └── webpack@5.76.1 deduped
│ ├─┬ source-map-loader@4.0.1
│ │ └── webpack@5.76.1 deduped
│ ├─┬ webpack-dev-middleware@6.0.1
│ │ └── webpack@5.76.1 deduped
│ ├─┬ webpack-dev-server@4.11.1
│ │ ├─┬ webpack-dev-middleware@5.3.3
│ │ │ └── webpack@5.76.1 deduped
│ │ └── webpack@5.76.1 deduped
│ ├─┬ webpack-subresource-integrity@5.1.0
│ │ └── webpack@5.86.0 deduped
│ └─┬ webpack@5.76.1
│   └─┬ terser-webpack-plugin@5.3.9
│     └── webpack@5.86.0 deduped
├─┬ @angular/animations@15.2.9
│ └── @angular/core@15.2.9 deduped
├─┬ @angular/common@15.2.9
│ └── @angular/core@15.2.9 deduped
├─┬ @angular/compiler@15.2.9
│ └── @angular/core@15.2.9 deduped
├── @angular/core@15.2.9
├─┬ @angular/forms@15.2.9
│ └── @angular/core@15.2.9 deduped
├─┬ @angular/platform-browser-dynamic@15.2.9
│ └── @angular/core@15.2.9 deduped
├─┬ @angular/platform-browser@15.2.9
│ └── @angular/core@15.2.9 deduped
├─┬ @angular/router@15.2.9
│ └── @angular/core@15.2.9 deduped
├── @ngx-env/builder@15.2.1
├─┬ @nrwl/angular@15.9.4
│ ├─┬ @nrwl/webpack@15.9.4
│ │ ├─┬ copy-webpack-plugin@10.2.4
│ │ │ └── webpack@5.86.0 deduped
│ │ ├─┬ css-loader@6.8.1
│ │ │ └── webpack@5.86.0 deduped
│ │ ├─┬ css-minimizer-webpack-plugin@3.4.1
│ │ │ └── webpack@5.86.0 deduped
│ │ ├─┬ file-loader@6.2.0
│ │ │ └── webpack@5.86.0 deduped
│ │ ├─┬ fork-ts-checker-webpack-plugin@7.2.13
│ │ │ └── webpack@5.86.0 deduped
│ │ ├─┬ mini-css-extract-plugin@2.4.7
│ │ │ └── webpack@5.86.0 deduped
│ │ ├─┬ postcss-loader@6.2.1
│ │ │ └── webpack@5.86.0 deduped
│ │ ├─┬ sass-loader@12.6.0
│ │ │ └── webpack@5.86.0 deduped
│ │ ├─┬ source-map-loader@3.0.2
│ │ │ └── webpack@5.86.0 deduped
│ │ ├─┬ style-loader@3.3.3
│ │ │ └── webpack@5.86.0 deduped
│ │ ├─┬ stylus-loader@7.1.3
│ │ │ └── webpack@5.86.0 deduped
│ │ ├─┬ ts-loader@9.4.3
│ │ │ └── webpack@5.86.0 deduped
│ │ └── webpack@5.86.0 deduped
│ └── webpack@5.86.0
├─┬ @po-ui/ng-components@15.9.2
│ ├─┬ @angular/cdk@15.2.9
│ │ └── @angular/core@15.2.9 deduped
│ └── @angular/core@15.2.9 deduped
├─┬ @po-ui/ng-templates@15.9.2
│ └── @angular/core@15.2.9 deduped
├─┬ @progress/kendo-angular-buttons@13.2.0
│ ├── @angular/core@15.2.9 deduped
│ ├─┬ @progress/kendo-angular-icons@13.2.0
│ │ └── @angular/core@15.2.9 deduped
│ └─┬ @progress/kendo-angular-schematics@13.2.0
│   └── @angular/core@15.2.9 deduped
├─┬ @progress/kendo-angular-common@13.2.0
│ └── @angular/core@15.2.9 deduped
├─┬ @progress/kendo-angular-dateinputs@13.2.0
│ ├── @angular/core@15.2.9 deduped
│ └─┬ @progress/kendo-angular-navigation@13.2.0
│   └── @angular/core@15.2.9 deduped
├─┬ @progress/kendo-angular-dropdowns@13.2.0
│ └── @angular/core@15.2.9 deduped
├─┬ @progress/kendo-angular-excel-export@13.2.0
│ └── @angular/core@15.2.9 deduped
├─┬ @progress/kendo-angular-grid@13.2.0
│ ├── @angular/core@15.2.9 deduped
│ └─┬ @progress/kendo-angular-utils@13.2.0
│   └── @angular/core@15.2.9 deduped
├─┬ @progress/kendo-angular-inputs@13.2.0
│ ├── @angular/core@15.2.9 deduped
│ ├─┬ @progress/kendo-angular-dialog@13.2.0
│ │ └── @angular/core@15.2.9 deduped
│ └─┬ @progress/kendo-angular-upload@13.2.0
│   └── @angular/core@15.2.9 deduped
├─┬ @progress/kendo-angular-intl@13.2.0
│ └── @angular/core@15.2.9 deduped
├─┬ @progress/kendo-angular-l10n@13.2.0
│ └── @angular/core@15.2.9 deduped
├─┬ @progress/kendo-angular-label@13.2.0
│ └── @angular/core@15.2.9 deduped
├─┬ @progress/kendo-angular-layout@13.2.0
│ └── @angular/core@15.2.9 deduped
├─┬ @progress/kendo-angular-pdf-export@13.2.0
│ └── @angular/core@15.2.9 deduped
├─┬ @progress/kendo-angular-popup@13.2.0
│ └── @angular/core@15.2.9 deduped
├─┬ @progress/kendo-angular-progressbar@13.2.0
│ └── @angular/core@15.2.9 deduped
├─┬ @progress/kendo-angular-treeview@13.2.0
│ └── @angular/core@15.2.9 deduped
├─┬ @testing-library/angular@14.1.1
│ └── @angular/core@15.2.9 deduped
├─┬ @totvs-supply/sl-base-foundation@15.0.0
│ └── @angular/core@15.2.9 deduped
├─┬ @totvs-supply/sl-kendo-grid@15.0.3
│ ├── @angular/core@15.2.9 deduped
│ └─┬ @progress/kendo-angular-treelist@13.2.0
│   ├── @angular/core@15.2.9 deduped
│   └─┬ @progress/kendo-angular-listview@13.2.0
│     ├── @angular/core@15.2.9 deduped
│     └─┬ @progress/kendo-angular-pager@13.2.0
│       └── @angular/core@15.2.9 deduped
├─┬ @totvs-supply/sl-web-foundation@15.0.1
│ └── @angular/core@15.2.9 deduped
├─┬ @totvs-supply/supply-access@15.0.1
│ ├── @angular/core@15.2.9 deduped
│ └─┬ angular-oauth2-oidc@15.0.1
│   └── @angular/core@15.2.9 deduped
├─┬ @totvs-supply/supply-host-config@15.0.1
│ └── @angular/core@15.2.9 deduped
├─┬ @totvs-supply/supply-oauth2@15.0.1
│ └── @angular/core@15.2.9 deduped
└─┬ jest-preset-angular@13.0.1
  └── @angular/core@15.2.9 deduped
chihab commented 1 year ago

hey, any chance to have repo or a stackblitz reproducing the issue?

bitbangx commented 1 year ago

@HuserOz if you have "files" or "include" options in your tsconfig, you may need to include your declaration file there, or it may be not picked up correctly

t-mish commented 9 months ago

Besides specifying paths in tsconfigs, you also need to update your nodejs and it's types definition (@types/node) to the newer ones. In my case, they were updated from 18.16.0 to 20.11.0.