Skip to content
This repository has been archived by the owner on May 1, 2020. It is now read-only.

Dev build/ionic serve fail when using globally-defined types. #163

Closed
JustinPierce opened this issue Oct 14, 2016 · 4 comments
Closed

Dev build/ionic serve fail when using globally-defined types. #163

JustinPierce opened this issue Oct 14, 2016 · 4 comments
Assignees

Comments

@JustinPierce
Copy link

Note: for support questions, please use one of these channels:

https://forum.ionicframework.com/
http://ionicworldwide.herokuapp.com/

Short description of the problem:

Using the ionic-app-scripts@0.0.33 (or any version greater than 0.0.30), building with --dev (and, by extension, ionic serve) will fail if you reference types that are defined globally. Specific examples that I've seen are @types/jasmine and @types/googlemaps. Neither of these packages declares a module that can be imported with an import statement.

A production build completes successfully, and a dev build completes successfully on ionic-app-scripts@0.0.30.

What behavior are you expecting?

I expect the build to complete successfully. 😉

Steps to reproduce:

  1. Create a test project (ionic start test --v2)
  2. Update dependencies to use ionic-app-scripts@0.0.33, if the starter still does not reference it.
  3. Optional sanity build (npm run build --dev). This build should be successful.
  4. Install a type definition that defines everything globally (npm install --save @types/googlemaps).
  5. Reference one of those types. I added public thingy: google.maps.places.PlaceResult = null; to src/pages/home/home.ts.
  6. Attempt a dev build. This build should fail with something similar to the following:
> ionic-hello-world@ build C:\Source\GitHub\test
> ionic-app-scripts build

[09:47:19]  ionic-app-scripts 0.0.33
[09:47:19]  build dev started ...
[09:47:19]  clean started ...
[09:47:19]  clean finished in 9 ms
[09:47:19]  copy started ...
[09:47:19]  transpile started ...
[09:47:19]  lint started ...
[09:47:21]  lint finished in 1.90 s
[09:47:22]  typescript: C:/Source/GitHub/test/src/pages/home/home.ts, line: 10
            Cannot find namespace 'google'.

       L9:  export class HomePage {
      L10:    public thingy: google.maps.places.PlaceResult = null;

[09:47:22]  transpile failed
[09:47:22]  ionic-app-script task: "build"
[09:47:22]  Error: Error

Which @ionic/app-scripts version are you using?

0.0.33

Other information: (e.g. stacktraces, related issues, suggestions how to fix, stackoverflow links, forum links, etc)

I'm developing on Windows. I haven't tried this on another OS, but I know there have been some Windows-specific issues with the last few versions of ionic-app-scripts.

@danbucholtz danbucholtz self-assigned this Oct 14, 2016
@jamesgroat
Copy link
Contributor

I needed to manually add src/declarations.d.ts to my project after upgrading to rc1 and I think that helped. You can see what the file looks like if you start a new blank rc1 project.

@JustinPierce
Copy link
Author

@jamesgroat I believe this is a slightly different issue. If there's something to add to declarations.d.ts for these particular libraries, then it's not clear what it is.

@JustinPierce
Copy link
Author

As a workaround for anyone having this issue, you can add the following to the compilerOptions section of tsconfig.json:

"types": [
  "jasmine",
  "googlemaps"
]

The values in the types array seem to match the names of the offending @types npm packages, but a quick search is revealing no documentation on this feature.

@danbucholtz
Copy link
Contributor

So, this isn't an actual bug, then. This is the desired behavior.

Going to close this issue for now. Perhaps we should document this better. This is a general Typescript thing, though.

Thanks,
Dan

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

No branches or pull requests

3 participants