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

Error: Cannot find module "@app/env" #34

Open
bhumin3i opened this issue Oct 30, 2018 · 4 comments
Open

Error: Cannot find module "@app/env" #34

bhumin3i opened this issue Oct 30, 2018 · 4 comments

Comments

@bhumin3i
Copy link

bhumin3i commented Oct 30, 2018

package.json


 "scripts": {
   "clean": "ionic-app-scripts clean",
   "build": "ionic-app-scripts build",
   "lint": "ionic-app-scripts lint",
   "ionic:build": "ionic-app-scripts build",
   "ionic:serve": "ionic-app-scripts serve",
   "debug:ios": "SENTRY_SKIP_AUTO_RELEASE=true ionic cordova prepare",
   "build:ios": "SENTRY_SKIP_AUTO_RELEASE=true ionic cordova build ios",
   "serve:prod": "LLI_ENV=prod ionic-app-scripts serve"
 },
"config": {
     "ionic_webpack": "./config/webpack.config.js",
     "ionic_generate_source_map": "true"
   },

weback.config.js

var chalk = require("chalk");
var fs = require('fs');
var path = require('path');
var useDefaultConfig = require('@ionic/app-scripts/config/webpack.config.js');

var env = process.env.LLi_ENV;

useDefaultConfig.prod.resolve.alias = {
  "@app/env": path.resolve(environmentPath('prod'))
};

useDefaultConfig.dev.resolve.alias = {
  "@app/env": path.resolve(environmentPath('dev'))
};

if (env !== 'prod' && env !== 'dev') {
  // Default to dev config
  useDefaultConfig[env] = useDefaultConfig.dev;
  useDefaultConfig[env].resolve.alias = {
    "@app/env": path.resolve(__dirname + 'config/config.' + process.env.LLi_ENV + '.ts'),
  };
}

function environmentPath(env) {
  var filePath = './src/environments/environment' + (env === 'prod' ? '' : '.' + env) + '.ts';
  if (!fs.existsSync(filePath)) {
    console.log(chalk.red('\n' + filePath + ' does not exist!'));
  } else {
    return filePath;
  }
}

module.exports = function () {
  return useDefaultConfig;
};

tsconfig.JSON

{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [
      "dom",
      "es2015"
    ],
    "module": "es2015",
    "moduleResolution": "node",
    "sourceMap": true,
    "target": "es5",
    "baseUrl": "./src",
    "paths": {
      "@app/env": [
        "environments/environment"
      ]
    }
  },
  "include": [
    "src/**/*.ts"
  ],
  "exclude": [
    "node_modules",
    "src/**/*.spec.ts",
    "src/**/__tests__/*.ts"
  ],
  "compileOnSave": false,
  "atom": {
    "rewriteTsconfig": false
  }
}

USE in my code

import { ENV } from '@app/env'; //error

SERVER_URL: string = ENV.mode;

@jiamoon
Copy link

jiamoon commented Nov 27, 2018

Have you solved this problem?

@bhumin3i
Copy link
Author

@jiamoon no still facing same :(

@Pietaman
Copy link

If your files in your "./src/environments" folder have a ".dev.ts" or ".prod.ts" extension, this does not match the path settings in tsconfig.json.
So either you have to use one file named "environments.ts" or you have to list (at least one) files in the tsconfig with an extension you are currently using.

@aronAtWex
Copy link

aronAtWex commented Apr 6, 2021

For some reason I just got this to happen to me. app/env just stopped working. Out of the blue when I build for ionic browser.
Works if I build local, find if I build for ios and android.

Cannot find module '@app/env' or its corresponding type declarations.

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

4 participants