-
Notifications
You must be signed in to change notification settings - Fork 818
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
Angular 4 Universal - SyntaxError: Unexpected token export #1052
Comments
Hello, I've had to deal with this issue which is not really an Agm issue but a global one. This was not an issue before Universal since there is always a bundle file in the packages for lets say System.js for local dev and Webpack/Rollup will understand es6 for production bundles. But with Universal, you directly use the files in the node_modules, in es6 then, and node do not know about Two things can be done, you can bundle your app even for universal, but you will lose a lot of compile time juste for a bundle that is useless in a server context. Other option, the one I used in my company, is to copy all your sources in a tmp folder before compile and create a node_modules folder in this tmp folder. This is super annoying and there is not really other options for now (let me know if you find a better one). I really think ng2 modules have to find a way to provide both es6 and commonjs files if they want their modules to be easy to use with universal :) |
Use webpack.config
|
@kkaabbaa can you confirm that this works? |
i have the same problem, i have babel and i did make a copy of the project in a new folder then a have babel locally installed but i would like to understand the process that Adrienboulle he mades for his company because i have to get finis this thing thank you in advance. |
i have add it to webpack.config and it dosen`t work for me. externals: [nodeExternals({ |
I have it working with a workaround by dynamically loading a component that contains my agm-map based on if it's the browser or server: https://angular.io/guide/dynamic-component-loader |
I have compiled to es5 but also showing error |
Finally able to use google map with universal. I am making repo and video |
I used this post https://medium.com/@evertonrobertoauler/angular-4-universal-app-with-angular-cli-db8b53bba07d and added
|
@kkaabbaa where did you add, please? |
My webpack.config.js |
Still not working , i tried @kkaabbaa solution , but didnot worked for me , same issue |
Updated the solution to the latest version of babel @philippeboyd @dkmostafa i solved the same issue recently for this module and others like --> ngx translate and more... solution (compile the js files into es2015):
|
@AnthonyNahas that is a very interesting idea. It seems too good to be true! I'll give it a go |
Anyone have a solution for this? Just recently encountered this as well. |
@adrienboulle thanks for explaining things, now I wonder: would it not be better to release the package in a different format that is also suitable for Angular Universal? That way all the workarounds circulating here would no longer be needed. Or would it be possible to make Angular Universal understand ES6 code? |
@AnthonyNahas I tried that. Now it shows another error
|
@AnthonyNahas, thank you so much for your solution! I tried several other solutions that didn't work for me for roughly one month! This actually solves my problem =) |
@karthikeyanmanureva u should do the same thing for antoher npm module which is throwing "SyntaxError: Unexpected token import" ... |
That means the babel compiler didn't do its job as it would have replaced the imports. Both repos should be available pre compiled in my github. You may use that if you are unable to do the babel part. |
@AnthonyNahas honestly thanks for your solution, it's working for me with latest version babel and angular 6. |
Your are a god my friend ... |
There is multiple issues preventing that package from being used on the server-side through Angular Universal. I've already did similar work on various libraries (e.g. salemdar/ngx-cookie#41, zefoy/ngx-perfect-scrollbar#129, mattlewis92/angular-resizable-element#80), so I thought I'd have a look. In short, when targeting the server platform with the Angular CLI only the app itself is compiled, as the library UMD bundle would then be used when running it in NodeJS. As pointed out by @AnthonyNahas, this means that the In addition to the NodeJS-native UMD bundle, best practices for libraries as per the Angular Package Format guidelines is to also publish AoT-friendly ES modules and The fix is to use In addition, the rollup configs were setting Last, now that your app universal build compiles with this library, you need to decide what to do at runtime / make the code itself Universal friendly, which I achieved using Anyway, the PR is at #1554, comments welcome. I have a fork running at @laurentgoudet/agm-core which I'm successfully using for my project (until this PR gets merged). I'm using the Angular CLI but it should work with any builder - feedback welcome. |
After a lot of tries, the solution provided by @AnthonyNahas allowed me to deploy a universal app as a firebase function :) . Edit (26/12/2018) |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Any activity on this? It is quite simple to fix - just need to start using
and starting use @angular-devkit/build-angular is quite simple and could save hours of hacking |
Thanks a lot, it's still work on Angular 7 |
Buts thats a hack... Or workaround...
…On Tue, Apr 2, 2019, 12:53 PM PEA ***@***.***> wrote:
@AnthonyNahas <https://github.com/AnthonyNahas>
*Updated the solution to the latest version of babel*
@philippeboyd <https://github.com/philippeboyd> @dkmostafa
<https://github.com/dkmostafa> i solved the same issue recently for this
module and others like --> ngx translate and more...
solution (compile the js files into es2015):
1. npm install --save-dev @babel/core @babel/cli @babel/preset-env
2. add this to the root project under the name .babelrc or add the
presets directly via cli
{ "presets": ***@***.***/preset-env"] }
3. add a npm script in package.json in "scrtipsts" scope
***@***.***_core": "babel ***@***.***/core -d
***@***.***/core --presets @babel/preset-env",
4. add a postinstall script in package.json in "scrtipsts" scope
"postinstall": "npm run ***@***.***_core",
5. run npm i to install the deps. After installing the deps, the
script postinstall will run and babel will compile the targeted js files
6. run your server and should world
7. Give me please feedback if it works. I did the same thins for more
than 3 npm modules it works on my machine :D
Thanks a lot, it's still work on Angular 7
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#1052 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADvMl79FA7YGEZN_DSvwaOsUS7zXFW9Rks5vczbEgaJpZM4OAQmB>
.
|
I've used the solution of @AnthonyNahas but I'm getting this error:
|
@HighSoftWare96 the problem is not related directly to the library... it seems to be a compile error... |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
We are going to move to ngc soon, so hopefully it will work with Angular Universal. Personally, I have 0 experience and knowledge in universal, and AoT. |
Ok, I pulled in ng-packagr PR, so maybe now it will work. Can you try forking master and seeing if it works? |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Hi @doom777 |
Not up to me |
Issue description
I'm unable to start my project in universal mode. However, when executing it in AOT with
ng serve
, all is well.Steps to reproduce and a minimal demo of the problem
Current behavior
Compiles but server cannot start
Expected/desired behavior
Server starting without errors
angular2 & angular-google-maps version
Other information
I've looked into issue #668 but it's doesn't seem to be the same issue...
The text was updated successfully, but these errors were encountered: