{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/21864","repository_url":"https://api.github.com/repos/Microsoft/TypeScript","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/21864/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/21864/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/21864/events","html_url":"https://github.com/Microsoft/TypeScript/issues/21864","id":296144005,"number":21864,"title":"SyntaxError: Unexpected token import","user":{"login":"Legends","id":966368,"avatar_url":"https://avatars1.githubusercontent.com/u/966368?v=4","gravatar_id":"","url":"https://api.github.com/users/Legends","html_url":"https://github.com/Legends","followers_url":"https://api.github.com/users/Legends/followers","following_url":"https://api.github.com/users/Legends/following{/other_user}","gists_url":"https://api.github.com/users/Legends/gists{/gist_id}","starred_url":"https://api.github.com/users/Legends/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Legends/subscriptions","organizations_url":"https://api.github.com/users/Legends/orgs","repos_url":"https://api.github.com/users/Legends/repos","events_url":"https://api.github.com/users/Legends/events{/privacy}","received_events_url":"https://api.github.com/users/Legends/received_events","type":"User","site_admin":false},"labels":[{"id":113971558,"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/Question","name":"Question","color":"d4c5f9","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2018-02-10T23:32:32Z","updated_at":"2018-02-12T00:04:14Z","closed_at":null,"author_association":"NONE","body":"**I want to export/import modules in a browser environment**\r\nI just updated node runtime to v9.5, but I had the issue with the previous version also.\r\n\r\n- C:\\WINDOWS\\system32>node -v v9.5.0\r\n- C:\\WINDOWS\\system32>npm -v 5.6.0\r\n- C:\\WINDOWS\\system32>tsc -v Version 2.7.1\r\n- Win 10 x64\r\n\r\n![image](https://user-images.githubusercontent.com/966368/36067676-10ab8202-0ec2-11e8-9c61-c3296b1baf78.png)\r\n\r\nWhen clicking the \"Play\" button in the upper right corner in VS Code. I get the error below. \r\nSometimes I can transpile it and sometimes not, it's weird.\r\n\r\nExpected behaviour: No transpile errors.\r\n\r\nWhat's wrong with the following code?\r\n\r\n> [Done] exited with code=1 in 1.229 seconds\r\n> \r\n> [Running] ts-node \"c:\\inetpub\\wwwroot\\TypeScriptTesting\\src\\app.ts\"\r\n> c:\\inetpub\\wwwroot\\TypeScriptTesting\\src\\app.ts:23\r\n> import * as _ from \"lodash\"; // import * as _ from \"lodash\" // npm install @types/lodash\r\n> ^^^^^^\r\n> \r\n> SyntaxError: Unexpected token import\r\n>     at new Script (vm.js:51:7)\r\n>     at createScript (vm.js:138:10)\r\n>     at Object.runInThisContext (vm.js:199:10)\r\n>     at Module._compile (module.js:624:28)\r\n>     at Module.m._compile (C:\\Users\\Admin\\AppData\\Roaming\\npm\\node_modules\\ts-node\\src\\index.ts:422:23)\r\n>     at Module._extensions..js (module.js:671:10)\r\n>     at Object.require.extensions.(anonymous function) [as .ts] (C:\\Users\\Admin\\AppData\\Roaming\\npm\\node_modules\\ts-node\\src\\index.ts:425:12)\r\n>     at Module.load (module.js:573:32)\r\n>     at tryModuleLoad (module.js:513:12)\r\n>     at Function.Module._load (module.js:505:3)\r\n\r\n\r\n**tsconfig.js**\r\n\r\n{\r\n    \"compilerOptions\": {\r\n        \"target\": \"es6\",\r\n        \"module\": \"es6\",\r\n        \"sourceMap\": true,\r\n        \"pretty\": true\r\n    },\r\n    \"include\": [\r\n        \"src/**/*\"\r\n    ],\r\n    \"exclude\": [\r\n        \"node_modules\",\r\n        \"**/*.spec.ts\"\r\n    ]\r\n}\r\n\r\n**other.ts**\r\n\r\n```\r\nexport module myModule {\r\n    export class Vehicle {\r\n        constructor(brand: string) {\r\n            this.Brand = brand;\r\n        }\r\n        Brand: string\r\n        Fueltype: string\r\n    }\r\n\r\n    export class Car extends Vehicle {\r\n        constructor(brand: string) {\r\n            super(brand);\r\n        }\r\n\r\n        run() {\r\n            console.log(\"We are driving a \" + this.Brand);\r\n        }\r\n    }\r\n}\r\n```\r\n\r\n**App.ts**\r\n\r\n```\r\nimport {myModule} from \"./other\";\r\n\r\nvar x = new myModule.Car(\"\");\r\n```\r\n\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/364803243","html_url":"https://github.com/Microsoft/TypeScript/issues/21864#issuecomment-364803243","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/21864","id":364803243,"user":{"login":"andy-ms","id":19274678,"avatar_url":"https://avatars3.githubusercontent.com/u/19274678?v=4","gravatar_id":"","url":"https://api.github.com/users/andy-ms","html_url":"https://github.com/andy-ms","followers_url":"https://api.github.com/users/andy-ms/followers","following_url":"https://api.github.com/users/andy-ms/following{/other_user}","gists_url":"https://api.github.com/users/andy-ms/gists{/gist_id}","starred_url":"https://api.github.com/users/andy-ms/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andy-ms/subscriptions","organizations_url":"https://api.github.com/users/andy-ms/orgs","repos_url":"https://api.github.com/users/andy-ms/repos","events_url":"https://api.github.com/users/andy-ms/events{/privacy}","received_events_url":"https://api.github.com/users/andy-ms/received_events","type":"User","site_admin":false},"created_at":"2018-02-12T00:04:14Z","updated_at":"2018-02-12T00:04:14Z","author_association":"CONTRIBUTOR","body":"Keep in mind this is an issue tracker, not a help forum. It's probably not a vscode bug, but a problem with the particular commands it was configured to use.\r\nYou said that you want to be working in a browser environment, so `ts-node` is probably not the tool you want to use, since it will run your code on the server using node. To run in a browser you would need to compile using webpack, rollup, or a similar tool that handles imports to produce a bundle, then reference that bundled `.js` code from your web app. You can still use source maps to be able to debug the original `.ts` code."}}
{"actor":{"display_login":"andy-ms"}}