user14579004
user14579004

Reputation:

TypeScript import doesn't work after compiling to JavaScript

starting-page.ts

export function startingPage () {...rest of function}

main.ts

import { startingPage } from "./starting-page";

startingPage();

index.html

<script src="/dist/main.js" type="text/javascript"></script>

Error:

 Uncaught SyntaxError: Cannot use import statement outside a module                         main.js:1

Description

I suppose it does not work because in JS files it should be module.exports = startingPage; as it is in my previous vanilla JS projects and it works just fine, however it is TS project and I have no idea how to make it work. edit: obviosuly, I am then importing it as const startingPage = requrie('...')

Upvotes: 0

Views: 536

Answers (1)

user14579004
user14579004

Reputation:

Solution to my problem was installing a Parcel - application bundler.

As I mentioned I used it in my vanilla JS projects, so I tried it also now, and it is working just fine. It was more of a JS syntax error than TS project build problem.

Upvotes: 2

Related Questions