components icon indicating copy to clipboard operation
components copied to clipboard

Unexpected token...

Open geelus opened this issue 10 years ago • 19 comments

I started a brand new angular2 project (beta 9) using the exact instructions on the angular.io website. Then added the angular2 material using your instructions. I'm getting unexpected token...

Any idea?

geelus avatar Mar 16 '16 07:03 geelus

Can you share your full error with us?

devversion avatar Mar 16 '16 12:03 devversion

test-app.zip Please download the attached file and run "npm install" and npm start" after extracting.

You will see the error.

Thanks in advance

geelus avatar Mar 16 '16 15:03 geelus

@geelus Please just post the error you're getting and when it occurs. It might be related to #167

jelbourn avatar Mar 16 '16 16:03 jelbourn

Thanks for your reply. I get the error as soon as I add the MdCheckBox as directive.

here is the error: Error: SyntaxError: Unexpected token <(…)Zone.run @ angular2-polyfills.js:1243zoneBoundFn @ angular2-polyfills.js:1220lib$es6$promise$$internal$$tryCatch @ angular2-polyfills.js:468lib$es6$promise$$internal$$invokeCallback @ angular2-polyfills.js:480lib$es6$promise$$internal$$publish @ angular2-polyfills.js:451lib$es6$promise$$internal$$publishRejection @ angular2-polyfills.js:401(anonymous function) @ angular2-polyfills.js:123Zone.run @ angular2-polyfills.js:1243zoneBoundFn @ angular2-polyfills.js:1220lib$es6$promise$asap$$flush @ angular2-polyfills.js:262Mutation (async)(anonymous function) @ angular2-polyfills.js:237asap @ angular2-polyfills.js:191scheduleMicrotask @ angular2-polyfills.js:129(anonymous function) @ angular2-polyfills.js:122lib$es6$promise$$internal$$fulfill @ angular2-polyfills.js:411lib$es6$promise$$internal$$resolve @ angular2-polyfills.js:392resolvePromise @ angular2-polyfills.js:516load @ system.src.js:1040xhr.onreadystatechange @ system.src.js:1061Zone.run @ angular2-polyfills.js:1243zoneBoundFn @ angular2-polyfills.js:1220XMLHttpRequest.send (async)fetchTextFromURL @ system.src.js:1085(anonymous function) @ system.src.js:1646lib$es6$promise$$internal$$initializePromise @ angular2-polyfills.js:515lib$es6$promise$promise$$Promise @ angular2-polyfills.js:806(anonymous function) @ system.src.js:1645(anonymous function) @ system.src.js:2667(anonymous function) @ system.src.js:3239(anonymous function) @ system.src.js:3506(anonymous function) @ system.src.js:3888(anonymous function) @ system.src.js:4347(anonymous function) @ system.src.js:4599(anonymous function) @ system.src.js:337Zone.run @ angular2-polyfills.js:1243zoneBoundFn @ angular2-polyfills.js:1220lib$es6$promise$$internal$$tryCatch @ angular2-polyfills.js:468lib$es6$promise$$internal$$invokeCallback @ angular2-polyfills.js:480lib$es6$promise$$internal$$publish @ angular2-polyfills.js:451(anonymous function) @ angular2-polyfills.js:123Zone.run @ angular2-polyfills.js:1243zoneBoundFn @ angular2-polyfills.js:1220lib$es6$promise$asap$$flush @ angular2-polyfills.js:262Mutation (async)(anonymous function) @ angular2-polyfills.js:237asap @ angular2-polyfills.js:191scheduleMicrotask @ angular2-polyfills.js:129(anonymous function) @ angular2-polyfills.js:122lib$es6$promise$$internal$$fulfill @ angular2-polyfills.js:411lib$es6$promise$$internal$$resolve @ angular2-polyfills.js:392resolvePromise @ angular2-polyfills.js:516load @ system.src.js:1040xhr.onreadystatechange @ system.src.js:1061Zone.run @ angular2-polyfills.js:1243zoneBoundFn @ angular2-polyfills.js:1220XMLHttpRequest.send (async)fetchTextFromURL @ system.src.js:1085(anonymous function) @ system.src.js:1646lib$es6$promise$$internal$$initializePromise @ angular2-polyfills.js:515lib$es6$promise$promise$$Promise @ angular2-polyfills.js:806(anonymous function) @ system.src.js:1645(anonymous function) @ system.src.js:2667(anonymous function) @ system.src.js:3239(anonymous function) @ system.src.js:3506(anonymous function) @ system.src.js:3888(anonymous function) @ system.src.js:4347(anonymous function) @ system.src.js:4599(anonymous function) @ system.src.js:337Zone.run @ angular2-polyfills.js:1243zoneBoundFn @ angular2-polyfills.js:1220lib$es6$promise$$internal$$tryCatch @ angular2-polyfills.js:468lib$es6$promise$$internal$$invokeCallback @ angular2-polyfills.js:480lib$es6$promise$$internal$$publish @ angular2-polyfills.js:451(anonymous function) @ angular2-polyfills.js:123Zone.run @ angular2-polyfills.js:1243zoneBoundFn @ angular2-polyfills.js:1220lib$es6$promise$asap$$flush @ angular2-polyfills.js:262

geelus avatar Mar 16 '16 16:03 geelus

@geelus try with the new alpha.1 release and let us know if it resolves your issue

jelbourn avatar Mar 16 '16 22:03 jelbourn

it doesn't work. What I have in my index.html is: System.config({ packages: {
app: { format: 'register', defaultExtension: 'js' }, '@angular2-material/core': { format: 'cjs', defaultExtension: 'js', main: 'core.js' }, '@angular2-material/checkbox': { format: 'cjs', defaultExtension: 'js', main: 'checkbox.js' }, } }); System.import('app/main') .then(null, console.error.bind(console));

Should I add anything else?

geelus avatar Mar 16 '16 23:03 geelus

Jeremy

I really appreciate for your helpfulness. Maybe I'm doing something wrong. Should I add any services to my bootstrap? Should I add any files to load in my index.html file?

Thanks

geelus avatar Mar 16 '16 23:03 geelus

@geelus I created a simple working app that consumes angular2-material from npm: https://github.com/jelbourn/material2-app

Let me know if that helps.

jelbourn avatar Mar 17 '16 00:03 jelbourn

Hi Jeremy I know it's simple for you but it's not following the angular2's website. It's using a server that I never heard of (ng server) and I'm completely lost how you made it work.

It works on my computer but when I try to use it in my project, it won't work. I'm sure all the people that use the Angular2's website startup project will have the same issues.

The file I attached earlier is exactly following the angular website's tutorials. So if you can make that work, it means everyone else would be able to use it.

Thanks, Morteza

geelus avatar Mar 17 '16 08:03 geelus

@geelus material2 is built with angular-cli, ng server is a web server from angular-cli. I guess, for now, you should use angular-cli commands to work with material2 rather than following angular2 site gudelines

m0t0r avatar Mar 17 '16 13:03 m0t0r

Vitaly, Thanks for the clarification. I've somehow got it working. Yea!!!

BUT at a price! I've copied the @angular2-material folder to the root folder of the application and it worked. I really don't know how but at least there is a way...

geelus avatar Mar 17 '16 13:03 geelus

@geelus it sounds like whatever server you're using just isn't configured to serve the assets brought into node_modules.

jelbourn avatar Mar 17 '16 17:03 jelbourn

Jeremy

I'm not using WHATEVER server. I'm using angular's recommended server which is the lite-server. This is why it's a good idea to have a solution for this. Completely up to you guys. I felt responsible to let you know of the issue.

Thank you for your help.

geelus avatar Mar 17 '16 21:03 geelus

@geelus Ah, I see. I hadn't seen that quick-start before. It should definitely be updated to use the angular-cli. All of this should be hammered out by the end of the beta phase. Thanks for pointing it out!

jelbourn avatar Mar 17 '16 21:03 jelbourn

Ah, Thanks for letting me know. I didn't know using the angular CLI is the best way. I thought it's an unimportant side project... My mistake :)

geelus avatar Mar 17 '16 21:03 geelus

@geelus The CLI is still pre-alpha, so it will be a bit before we really start promoting it, but it's useful for very simple apps.

jelbourn avatar Mar 17 '16 21:03 jelbourn

Alright then I'll wait for it. At least now I know that's the future...

geelus avatar Mar 17 '16 22:03 geelus

Is there a root cause for this one? We are getting the same problem.

I could really use help from someone who has gotten past this without the CLI.

It is almost sounding like the CLI use is a crutch to get past this. There are a number of us who are trying to add material2 into existing angular2 applications which are not using the CLI.

ddjonline avatar Sep 09 '16 17:09 ddjonline

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.