0

Here is my intention Add two typescript files say: 1- app.ts and 2- decorator.ts, app.ts uses a class defined in decorator.ts.

I am trying to create a simple sample without the use of module loader so I thought in my HTML I'd add the scripts.js file references in correct order but it will work, but no I got ReferenceError: exports is not defined

My project is a ASP.NET Core Web application with static files only. I have hosted the full code on github here.

I am thinking it would work fine if I use a module loader, is this true? Can I not use these two scripts without a module loader and simple includes?

2
  • You could try setting --module to none, or try --outFile. But really, I would just use Parcel which can bundle up your code without any configuration at all. Commented Sep 16, 2018 at 0:17
  • @Aaron thanks. My intention is to not use any module loader or web pack. Commented Sep 16, 2018 at 0:22

1 Answer 1

2

If you want to include the two JavaScript files with individual <script> tags and have them be able to access each other's definitions, you'll need to make them not modules by removing the imports and exports. Then Decorator will be defined globally and the second JavaScript file can access it by that name without importing. Furthermore, app will be defined globally so that your onload handler can call it. If you don't want to define a huge number of globals, consider using a namespace, which will effectively group all your definitions under a single global name.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.