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

Cannot find module './.env' or its corresponding type declarations #575

Closed
1 of 4 tasks
Wintermute79 opened this issue Nov 5, 2020 · 7 comments
Closed
1 of 4 tasks

Comments

@Wintermute79
Copy link

I'm submitting a...

  • Bug report
  • Feature request
  • Documentation issue or request
  • Question

Current behavior

On very first npm start right after creating a new project, I get the following error:

ERROR in src/environments/environment.ts:11:21 - error TS2307: Cannot find module './.env' or its corresponding type declarations.

11 import { env } from './.env';

Expected behavior

no error message

Minimal reproduction of the problem with instructions

  1. npm install -g generator-ngx-rocket
  2. ngx new
  3. npm start

Environment



ngX-Rocket: 9.1.0
Node.js: v15.0.1
Npm: 7.0.3
OS: win32 x64 10.0.19041

Generated project options:
{
  "generator-ngx-rocket": {
    "version": "9.1.0",
    "props": {
      "location": "path",
      "strict": false,
      "skipInstall": false,
      "skipQuickstart": false,
      "initGit": true,
      "usePrefix": true,
      "appName": "rocket2",
      "target": [
        "web"
      ],
      "pwa": false,
      "ui": "ionic",
      "layout": "side-menu",
      "auth": false,
      "lazy": false,
      "angulartics": false,
      "languages": [
        "de-DE",
        "en-US"
      ],
      "tools": [
        "prettier",
        "hads"
      ],
      "utility": [
        "lodash"
      ],
      "deploy": "none",
      "projectName": "rocket-2",
      "packageManager": "npm",
      "mobile": [],
      "desktop": []
    }
  }
}

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 10.1.7
Node: 15.0.1
OS: win32 x64

Angular: 10.2.2
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: Yes

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1001.7
@angular-devkit/build-angular   0.1001.7
@angular-devkit/core            10.1.7
@angular-devkit/schematics      10.1.7
@angular/cli                    10.1.7
@schematics/angular             10.1.7
@schematics/update              0.1001.7
rxjs                            6.6.3
typescript                      4.0.5

@Wintermute79
Copy link
Author

Here is another user that obviously had encountered this behavior before:
https://stackoverflow.com/a/57115209/467341

@jiniguez
Copy link

I have found the same issue and I think this might be a npm bug.

@Wintermute79 Can you try executing npm run env ?

I am running npm 7.0.14 in Windows 10 and I get a list of environment variables. However, according to npm documentation:

The env script is a special built-in command that can be used to list environment variables that will be available to the script at runtime. If an "env" command is defined in your package, it will take precedence over the built-in.

Rocket has an "env" command defined in package.json but still does not take precendence over the built in command.

If you edit package.json and change the script name from env to env-fix, for example, running npm run env-fix works as intended and creates the missing environment file.

@Wintermute79
Copy link
Author

Thank you so much @jiniguez , that solves it.

Running npm run env just outputs my environment variables instead of executing the script defined in package.json.

Once I rename env (and all occurences) to env-fix in package.json as you suggested, it works.
So the important line becomes:
"env-fix": "ngx-scripts env npm_package_version"

Then the .env.ts file in src/environments is created as intended by npm run env-fix

I am running npm 7.0.3 and node 15.0.1 on Windows 10.

@Mef45
Copy link

Mef45 commented Dec 8, 2020

I have the same issue

ngx-rocket/scripts#21

@joboyx
Copy link

joboyx commented Dec 26, 2020

Thank you so much @jiniguez , that solves it.

Running npm run env just outputs my environment variables instead of executing the script defined in package.json.

Once I rename env (and all occurences) to env-fix in package.json as you suggested, it works.
So the important line becomes:
"env-fix": "ngx-scripts env npm_package_version"

Then the .env.ts file in src/environments is created as intended by npm run env-fix

I am running npm 7.0.3 and node 15.0.1 on Windows 10.

Also encountered the issue and renaming "env" script to something else worked.

I'm running in MacOS 11.1; npm 7.0.8; node v15.2.1.

image

@sinedied sinedied added the bug label Jan 5, 2021
@sinedied
Copy link
Member

sinedied commented Jan 5, 2021

Thanks for pinpointing the issue and the fix, I could never reproduce this one!
Will push a fix.

ci-rebot pushed a commit that referenced this issue Jan 14, 2021
# [9.2.0](9.1.0...9.2.0) (2021-01-14)

### Bug Fixes

* app not loading with Electron v11 ([1444bf0](1444bf0))
* incorrect hads version ([ba20ff1](ba20ff1))
* rename env script to fix execution in some environments (closes [#575](#575)) ([ec93fdb](ec93fdb))
* update electron templates ([3433465](3433465))
* update generator dependencies ([bda29d9](bda29d9))
* update jest config ([4b4a357](4b4a357))
* update packages and fix peer dependencies ([64098dc](64098dc))
* update RouteReusableStrategy for Angular 11 ([#576](#576)) ([3077f5b](3077f5b))

### Features

* add brazilian portuguese language ([1a6d728](1a6d728))
* enable webpack 5 ([8592a71](8592a71))
* migrate to @ngneat/until-destroy (fix [#577](#577)) ([3a77fcb](3a77fcb))
* update editorconfig (fixes [#580](#580)) ([9f036b3](9f036b3))
@ci-rebot
Copy link
Collaborator

🎉 This issue has been resolved in version 9.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

No branches or pull requests

6 participants