gshigeto / ionic-environment-variables

Easy to use environment variables for Ionic3!
MIT License
277 stars 36 forks source link

Cannot find module '@app/env'. #21

Closed wiadev closed 6 years ago

wiadev commented 6 years ago

I've followed your steps but got the error can't find a module.

I've kept the config.dev.ts and config.prod.ts under ./config. tsconfig.json

"baseUrl":  "./config",
    "paths": {
      "@app/env": ["config"]
    },

webpack.config.js

var path = require('path');
var useDefaultConfig = require('@ionic/app-scripts/config/webpack.config.js');
module.exports = function () {
    useDefaultConfig[process.env.IONIC_ENV].resolve.alias = {
        "@app/env": path.resolve(__dirname + '/config.' + process.env.IONIC_ENV + '.ts'),
    };
    return useDefaultConfig;
};

These are the same as you mentioned in README but still can't find a module.

Ionic v3.9.3

Robinyo commented 6 years ago

See:

enolcasielles commented 6 years ago

Have you put baseUrl and paths inside compilerOptions object in tsconfig.json file? I had same error and this was the reason.

wiadev commented 6 years ago

@enolcasielles yes, I did.

"baseUrl":  "./config",
    "paths": {
      "@app/env": ["config"]
    },

I've followed the example in readme precisely and it worked but not sure why the above case is not working.

enolcasielles commented 6 years ago

Could be because you are indexing file from root directory instead config folder? Maybe you should change by:

"@app/env": path.resolve(__dirname + 'config/config.' + process.env.IONIC_ENV + '.ts'),

wiadev commented 6 years ago

@enolcasielles Thanks

aronAtWex commented 3 years ago

Out of the blue I'm getting the same problem. Google lead me here.

Created a new thread
https://github.com/gshigeto/ionic-environment-variables/issues/39

0x14Rp commented 3 years ago

Could be because you are indexing file from root directory instead config folder? Maybe you should change by:

"@app/env": path.resolve(__dirname + 'config/config.' + process.env.IONIC_ENV + '.ts'),

this solution is not working?i am looking for something so i need to change environments when doing the build