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

the latest version cannot work in ng2+, npm install result is not complete #738

Open
xmeng1 opened this issue Oct 4, 2017 · 10 comments
Open

Comments

@xmeng1
Copy link

xmeng1 commented Oct 4, 2017

The last version 'npm install' the package in node_modules is not complete:
version 2.0.4
selection_041

version 2.0.3
selection_042

So with the latest version in Angular2+, the swal cannot be found and imported.

@t4t5
Copy link
Owner

t4t5 commented Oct 4, 2017

The src folder should not be necessary for using SweetAlert in a project. When you use import swal from 'sweetalert' it should pull the file from the dist folder. Are you sure it doesn't work when you try?

@xmeng1
Copy link
Author

xmeng1 commented Oct 4, 2017

I have tried use angular CLI 1.3.2 to create a clean project and npm install the latest of sweetalert. I cannot import swal and error has been displayed in the picture (after change to 2.0.3, the error was gone).

Is there any change for usage for angular 2+?

@t4t5
Copy link
Owner

t4t5 commented Oct 4, 2017

It shouldn't matter which Angular version you use since SweetAlert just uses simple ES imports. I don't see any error in your screenshots so I'm going to go ahead and close this.

@t4t5 t4t5 closed this as completed Oct 4, 2017
@xmeng1
Copy link
Author

xmeng1 commented Oct 4, 2017

selection_043

@t4t5
Copy link
Owner

t4t5 commented Oct 4, 2017

Thanks, I see the problem now. Will investigate!

@t4t5 t4t5 reopened this Oct 4, 2017
@xmeng1
Copy link
Author

xmeng1 commented Oct 4, 2017

OK thanks

@t4t5
Copy link
Owner

t4t5 commented Oct 4, 2017

Alright, I just published v2.0.5 on NPM. Try to download that and try again. Also, make sure that you add the following line in your project's tsconfig.json:

    "allowSyntheticDefaultImports": true,

@xmeng1
Copy link
Author

xmeng1 commented Oct 4, 2017

Thanks. I have tried it
If I import swal as follow:

import * as swal from 'sweetalert';

it works perfect.

But if I import it as previous:

import swal from 'sweetalert';

There is still an error as follows, I think the sweetalert.d.ts should export default class swal, then the swal can be imported directly according to this microsoft/TypeScript#3337
image

@itanimo
Copy link

itanimo commented Oct 18, 2017

same issue as @xmeng1 , only import as works

@xmeng1
Copy link
Author

xmeng1 commented Oct 20, 2017

change sweetalert.d.ts to this code, then swal can be imported directly

//export = swal;
export as namespace swal;
export default swal;

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

3 participants