generator-ko icon indicating copy to clipboard operation
generator-ko copied to clipboard

Unexpected token import

Open zantinger opened this issue 8 years ago • 8 comments

Hi, I have run the generator successfully. Now, when I run http-server for src on the cmd I get an error Unexpected token import in startup.js. Same problem in Chrome 50 and Firefox on win10

zantinger avatar May 17 '16 09:05 zantinger

Yes me too - stops on the import 'jquery'; statement, line 1 of the startup.js

sportechrobbie avatar May 19 '16 16:05 sportechrobbie

The only way i could get this to run in my browser (Chrome) was to do the build, by running the gulp command and pointing my browser to the 'dist' folder - it seems the ES2015 change has something todo with it.

sportechrobbie avatar May 20 '16 10:05 sportechrobbie

Just watched the video online today and tried deploying KO application using this generator. Ran into this issue where browser JS engine is complaining about import statements. Then tried compiling in Babel via Gulp script but hit Issue #19 in the process. Is this generator left for dead?

chrconlo avatar May 20 '16 20:05 chrconlo

Facing same problem, someone still maintaining this project?

yskeat avatar May 31 '16 00:05 yskeat

This change looks like it was on purpose...to make this generator useless for people who just want to use plain JavaScript. Now struggling to get ko.mapping to work with ko components generated with this tool. I am quickly coming to the conclusion I should have bit the bullet and learned Angular...

chrconlo avatar Jun 06 '16 15:06 chrconlo

Hey guys, there is a fix to this I found on SO. Well... there is a fix to getting the Gulp build to work anyway. Its a pretty simple fix and relates to how slashes are handled between windows and OSX.

At the top of gulpfile.js you need to add the following variable to the gulp and plugins variables: slash = require('slash');

Then at the bottom of the file edit the babelTranspile function. Add a new line at the top of the function and paste the following: pathname = slash(pathname);

This will allow the build to execute and the application will load from the dist folder. I have no idea how steve is running from the src folder in the demo however. No browsers support ES6 so the imports declarations in the startup file in my mind will never work, they would have to be updated to ES5 require statements.

Original answer to the gulp problem found here:

http://stackoverflow.com/questions/33198584/gulp-failing-default-task-due-to-jquery-error-for-generator-ko

Kevinio04 avatar Jun 17 '16 15:06 Kevinio04

I'm stuck on this too. I can only get it to run if I build with Gulp. I was so looking forward to using this. But it just doesn't seem to be complete.

I also thought this was ready for TypeScript??

cosmoKenney avatar Jan 11 '17 04:01 cosmoKenney

@Kevinio04 I spend almost day to resolve same issue. Thanks for your solution, its works :) 👍

dipaktelangre avatar Feb 23 '17 10:02 dipaktelangre