Skip to content

beta.4/5 cannot resolve client classes (nor window) in environment.dev.ts #833

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

Closed
sgbeal opened this issue May 19, 2016 · 11 comments
Closed
Labels
effort2: medium (days) P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@sgbeal
Copy link

sgbeal commented May 19, 2016

Please provide us with the following information:

  1. OS? Windows 7, 8 or 10. Linux (which distribution). Mac OSX (Yosemite? El Capitan?)

Windows 10 (running in admin mode)

  1. Versions. Please run ng --version. If there's nothing outputted, please
  2. Repro steps. Was this an app that wasn't created using the CLI? What change did you
    do on your code? etc.

we import client-side classes in environment.dev.ts. In angular-cli versions newer than 1.0.0-beta.1, those imports cannot be resolved at build-time. It also cannot resolve 'window', so it's not a problem with our classes.

Log

with 1.0.0-beta.1:

    $ ng build
    (node:9540) fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module, please update it to a more recent version.
    Built project successfully. Stored in "dist/".

    stephan@Curie MINGW64 /d/src/.../nms-gui (my-branch)
    $ ng --version
    (node:6200) fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module, please update it to a more recent version.
    angular-cli: 1.0.0-beta.1
    node: 6.1.0
    os: win32 x64

with 1.0.0-beta.4: (edit: same result with beta.5)

    stephan@Curie MINGW64 /d/src/.../nms-gui (my-branch)
    $ npm install
    npm WARN deprecated [email protected]: This package has been discontinued in favor of lodash@^4.0.0.
    npm WARN deprecated [email protected]: cross-spawn no longer requires a build toolchain, use it instead!
    npm WARN deprecated [email protected]: graceful-fs v3.0.0 and before will fail on node releases >= v7.0. Please update to graceful-fs@^4.0.0 as soon as possible. Use 'npm ls graceful-fs' to find it in the tree.

    > [email protected] postinstall D:\src\...\nms-gui
    > typings install


    ├── es6-shim (ambient)
    ├── angular-protractor (ambient dev)
    ├── jasmine (ambient dev)
    └── selenium-webdriver (ambient dev)

    [email protected] D:\src\...\nms-gui
    `-- [email protected]
      `-- [email protected]
        +-- [email protected]
        | +-- [email protected]
        | | +-- [email protected]
        | | `-- [email protected]
        | +-- [email protected]
        | `-- [email protected]
        `-- [email protected]
          +-- [email protected]
          +-- [email protected]
          `-- [email protected]
            `-- [email protected]

    npm WARN optional Skipping failed optional dependency /chokidar/fsevents:
    npm WARN notsup Not compatible with your operating system or architecture: [email protected]
    npm WARN optional Skipping failed optional dependency /browser-sync/chokidar/fsevents:
    npm WARN notsup Not compatible with your operating system or architecture: [email protected]

    stephan@Curie MINGW64 /d/src/.../nms-gui (my-branch)
    $ ng --version
    (node:8100) fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module, please update it to a more recent version.
    angular-cli: 1.0.0-beta.4
    node: 6.1.0
    os: win32 x64

    stephan@Curie MINGW64 /d/src/.../nms-gui (my-branch)
    $ ng build
    (node:10520) fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module, please update it to a more recent version.
    Cannot find module './services/core/logger'
    Error: Cannot find module './services/core/logger'
        at Function.Module._resolveFilename (module.js:438:15)
        at Function.Module._load (module.js:386:25)
        at Module.require (module.js:466:17)
        at require (internal/module.js:20:19)
        at Object.<anonymous> (D:\src\...\nms-gui\config\environment.dev.ts:5:16)
        at Module._compile (module.js:541:32)

it's complaining about the first import it finds. It also cannot resolve 'window' or 'console'.

  1. The log given by the failure. Normally this include a stack trace and some
    more information.

see above.

  1. Mention any other details that might be useful.

Works fine with 1.0.0-beta.1.

@sgbeal
Copy link
Author

sgbeal commented May 19, 2016

i tried removing all references to our classes, but then it died on a reference to 'window'.

@sgbeal sgbeal changed the title beta.4 cannot resolve client classes (nor window) in environment.dev.ts beta.4/5 cannot resolve client classes (nor window) in environment.dev.ts May 23, 2016
@filipesilva
Copy link
Contributor

I think I know what's happening. The env files are being compiled in place instead of in the target directory, and because of that they can't find relative module paths.

I'm working on a solution for this issue, using conditional module mapping via SystemJS rather than moving files around, I hope to have the PR ready later this week.

@sgbeal
Copy link
Author

sgbeal commented May 23, 2016

To reproduce, simply add this to one of the env files:

if(window.location){ console.log("!!!"); }

leads to:

ReferenceError: window is not defined
    at Object.<anonymous> (D:\src\...\nms-gui\config\environment.prod.ts:6:5)

@sgbeal
Copy link
Author

sgbeal commented May 23, 2016

@filipesilva a declare unfortunately doesn't suffice...

environment.prod.ts:

    //import {Injector} from '@angular/core';
    //noinspection TypeScriptCheckImport
    //import {LogService} from "./services/core/logger";
    declare var LogService: any;
    //declare var Injector: any;
    export const environment = {
        production: true,
        // No-op in prod build.
        addEnvironmentProviders: function (providers:any[]/*ignored*/){},
        // LogService default logging level config...
        LogService:{
            enabled: {
                debug: true,
                info: true,
                warn: true,
                error: true
            }
        },
        // called by the app bootstrapping process.
        doEnvironmentSetup: function(injector:any){
            injector.get(LogService).setPrefix('LogService').enable(this.LogService.enabled)
                .debug("Please turn off debug logging in production mode (see environment.prod.ts).");
        }
    };
    LogService.setEnabledDefaults(environment.LogService.enabled);

Build result:

    ReferenceError: LogService is not defined
        at Object.<anonymous> (D:\src\...\config\environment.prod.ts:24:1)

line 24 is the call to injector.get()

@filipesilva
Copy link
Contributor

Yeah I don't think that the env files can be used to import services stuff in right now, due to how the module resolution is configured.

I'm thinking of reworking it this week, but in the meanwhile the best advice I can give to use the newer betas is to set a variable for your environment in environment.*.ts and use it somewhere else (like main) in an if to choose which init logic to run.

@sgbeal
Copy link
Author

sgbeal commented May 23, 2016

It did work until beta.5 :/. The problem with simply setting a flag is that we are forced to send all of our client-side mock data in prod builds if we do that. We could live with that if there's no other way, but... it worked fine before b5 :/. This setup allowed us to import the client-side mock (and its data) only in dev builds.

Okay, i'll rework it to use no imports in environment, but that sorely limits the true utility of env.xxx.ts (as they're now effectively limited to holding only constant values).

@filipesilva
Copy link
Contributor

If you can wait a week-ish, I think I'll be able to have better env file support that should be able to fully cover your use-case.

@sgbeal
Copy link
Author

sgbeal commented May 23, 2016

i can, but the project can't - we go in ~13 working days. i just discovered that 1.0.x doesn't work for us at all (-prod build succeeds but is missing files: see #847 for details), and am currently rolling back to 0.0.34. i will refactor our env to simply include everything and toggle it on or off - not a major problem.

@filipesilva
Copy link
Contributor

I haven't had a change to work more on this, but just want to link here a related issue: #933

@filipesilva filipesilva added effort2: medium (days) P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent labels Jun 4, 2016
@filipesilva
Copy link
Contributor

Closed via #1455. Environments are now in the right folder. window and console are also included via the tsconfig libs option.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
effort2: medium (days) P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
Development

No branches or pull requests

2 participants