Reputation: 11
Problem every time i use the word export in TS with unexpected token export.
Using typescript. Files have ts extension. Editor: VSC. Installed nodejs, angular, typescript etc. following the udemy course ive bought (too bad they dont reply to questions there). I am huge beginner and would like, if possible, get very simple answer (i know only Python and some Java). Problem on two computers, 3 different OS (including VM with Ubuntu)
Before i start i want to say ive searched all the google and SO similar questions. Reading them was like reading Chineese, i got nothing and those commands didnt help. My problem is like this:
console.log("hello world");
let x = 20;
The moment i run this everything is fine (i run this via vsc terminal, command ts-node). The moment i add export before the variable i get the error ive written in the title. This isnt problem with variables only. At first i wanted to export and import a class (as in the introduction to the course on udemy ive bought). Everything worked fine until exports.
I created angular ng app (just like project in Djnago for example) but never got to changing anything in the files - during the introduction i was making ts files in a dir named sandbox and running them using ts-node command. Everything worked fine until exports. Its not even problem with importing, attempt to export something is enough reason to give that error. Just like below:
console.log("hello world");
export let x = 20;
(i wrote that as i remember it (files are in my VM, cant copy them) but the syntax was correct. Or at least - the same as in my Udemy course. Other ppl had this problem as well (no one got the reply alas).
This is my first post on SO. I do use it only if i have to and I never even needed to create an account and ask about anything. But this time im totally lost. If someone can, please help me. Im doing everything as in tutorial and idk why its not working. Idk about different versions of JS, frameworks etc. I was just simply following instructions that should work but they don't. If necessary, i can write down exactly all that i did, how i got it installed or provide any other information. Just please help.
Btw: Angular 10.1.6, npm: 6.14.4, tsc: 4.0.3. Both windows and linux (ubuntu) gives the same errors. Editor:VSC. Installed Angular, node.js and everything yesterday (on ubuntu today, the only difference was sudo before npm install commands) so it should all be up to date (if its not, im very surprised).
EDIT:
Thank you for answer. Here is an export with the class. Dont work as well:
export class Cust extends Persona {
constructor(name:string, age:number, private advisor:string)
{
super(name, age);
}
welcome(): string {
return `Hello from ${this.name}, advised by ${this.advisor}}`;
}
}
Everything just like in an Udemy course... :(
EDIT2:
package.json:
{
"name": "test",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "~10.1.5",
"@angular/common": "~10.1.5",
"@angular/compiler": "~10.1.5",
"@angular/core": "~10.1.5",
"@angular/forms": "~10.1.5",
"@angular/platform-browser": "~10.1.5",
"@angular/platform-browser-dynamic": "~10.1.5",
"@angular/router": "~10.1.5",
"rxjs": "~6.6.0",
"tslib": "^2.0.0",
"zone.js": "~0.10.2"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.1001.6",
"@angular/cli": "~10.1.6",
"@angular/compiler-cli": "~10.1.5",
"@types/node": "^12.11.1",
"@types/jasmine": "~3.5.0",
"@types/jasminewd2": "~2.0.3",
"codelyzer": "^6.0.0",
"jasmine-core": "~3.6.0",
"jasmine-spec-reporter": "~5.0.0",
"karma": "~5.0.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage-istanbul-reporter": "~3.0.2",
"karma-jasmine": "~4.0.0",
"karma-jasmine-html-reporter": "^1.5.0",
"protractor": "~7.0.0",
"ts-node": "~8.3.0",
"tslint": "~6.1.0",
"typescript": "~4.0.2"
}
}
EDIT3: tsconfig.json
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"importHelpers": true,
"target": "es2015",
"module": "es2020",
"lib": [
"es2018",
"dom"
]
}
}
PS.Those are files from my computer, i cant copy-paste files from my VM. But it doesnt work on both computers and VM as well. Here are configs from the device i was providing examples with.
angular:
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"test": {
"projectType": "application",
"schematics": {},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/test",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.app.json",
"aot": true,
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.css"
],
"scripts": []
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"budgets": [
{
"type": "initial",
"maximumWarning": "2mb",
"maximumError": "5mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "6kb",
"maximumError": "10kb"
}
]
}
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "test:build"
},
"configurations": {
"production": {
"browserTarget": "test:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "test:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.spec.json",
"karmaConfig": "karma.conf.js",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.css"
],
"scripts": []
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"tsconfig.app.json",
"tsconfig.spec.json",
"e2e/tsconfig.json"
],
"exclude": [
"**/node_modules/**"
]
}
},
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "e2e/protractor.conf.js",
"devServerTarget": "test:serve"
},
"configurations": {
"production": {
"devServerTarget": "test:serve:production"
}
}
}
}
}},
"defaultProject": "test"
}
EDIT: Never in my life have i thought running simple export command in TS requires Phd in Computer Science....
Upvotes: 0
Views: 866
Reputation: 42170
Edit:
This did not resolve the problem, @Konrad J. is not able to use export const
or export class
either and I am at a loss!
Original Response:
I won't get into the nitty-gritty since you're a beginner, but you cannot export let
. You can however export const x = 20;
If you want the details, check out:
Upvotes: 1