Skip to content

Not compatible with Angular 2 AoT (Ahead-of-time compilation) #787

Description

@adrienverge

TL;DR: Angular 2 AoT requires es2015 compilation and raven-js Typescript import is not
compatible with es2015 anymore.

Hi,

Before you ask, I've been through #752, #735, #643 and recent changes to raven-js + Angular 2 documentation.

As explained in Angular 2 AoT docs, module MUST be set to es2015 in tsconfig.json. Just in case, I tried commonjs or system: both failed as expected.

The problem is: since commit 05ebd0 (I think), raven-js import method is not compatible with es2015. (This commit changed the definition file from export default Raven to export = Raven.)

When using import Raven from 'raven-js';, the compiler says:

error TS1192: Module '".../node_modules/raven-js/typescript/raven"' has no default export.

When using import Raven = require('raven-js');:

error TS1202: Import assignment cannot be used when targeting ECMAScript 2015 modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.

And using import * as Raven from 'raven-js'; does not work with:

System.config({
  packages: { 'raven-js': { main: 'dist/raven.js' } },
  paths: { 'raven-js': 'node_modules/raven-js' }
});

I'd be happy to provide more information if needed.

Activity

  1. benvinegar commented on Dec 2, 2016

    @benvinegar
    Contributor

    To clarify, your suggestion is put it back the way it was (before 05ebd0)? Or should we have a proper ES2015 module export file for that platform somewhere?

    Basically, we're struggling with the TypeScript definition file. I basically kept tweaking things until I could get it loading in every possible loader. But it's becoming harder and harder to keep up with all of this. If someone from the Angular or TypeScript community could give us a definitive best practice for how the typings file should work, we'd be glad to make the requisite changes.

  2. adrienverge commented on Dec 3, 2016

    @adrienverge
    Author

    Hi @benvinegar, thanks for your answer.

    I've spent a lot of time on this and I now see two points here:

    1. Should SystemJS be used to load raven-js bundle?

    First, as copied from here, raven-js is a third party global resource. The Raven object lives on window in the browser. Therefore it is maybe not correct to import it in an Angular 2 application.

    So I'm wondering whether it's correct or not to load it from SystemJS using System.config({ packages: { 'raven-js': { main: 'dist/raven.js' } } ...; maybe the best way is to import it through <script src="/node_modules/raven-js/dist/raven.min.js"></script> in the HTML file, leave systemjs.config.js alone, and let good old typings do the job at compilation time.

    What do you think? @Chuckv01 @NoNameProvided @davorpeic

    2. Typings shipped with raven-js

    I really don't think import Raven = require('raven-js'); is the "normal" way to import a bundled JS library. Most libs I've seen define modules in their declaration files, so they can be imported in many fashions (including import Raven from 'raven-js';).

    I'm working on a rewriting of the .d.ts file, I'd be happy to make a pull-request depending on the output of this dicussion. It would look like:

    declare module "raven-js" {
        export default ravenjs;
    }
    
    declare module ravenjs {
        interface RavenStatic { ... }
        interface RavenOptions { ... }
        ...
    }
    
    declare var Raven: ravenjs.RavenStatic;
  3. NoNameProvided commented on Mar 1, 2017

    @NoNameProvided

    Just a heads up, it's compatible now, so the issue can be closed.

  4. benvinegar commented on Mar 2, 2017

    @benvinegar
    Contributor

    Sweet.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions