Parcel: Basic TypeScript example not working `define is not defined`

Created on 24 Dec 2017  路  5Comments  路  Source: parcel-bundler/parcel

Create HTML page with TypeScript script

index.ts

alert('hi')

It fails with Uncaught ReferenceError: define is not defined

馃帥 Configuration (.babelrc, package.json, cli command)

No babel config or package.json

馃實 Your Environment

Mac OS, Node 9.3

parcel 1.3.1

More

The content of the build https://gist.github.com/alexeypetrushin/2d3a2a5dabddc34afd0ba09ed02f14b4

There's no declaration for define function

Most helpful comment

Maybe try setting your tsconfig.json to use commonjs, as it looks like it's using AMD by default for some reason.

{
  "compilerOptions": {
    "module": "commonjs"
  }
}

All 5 comments

Maybe try setting your tsconfig.json to use commonjs, as it looks like it's using AMD by default for some reason.

{
  "compilerOptions": {
    "module": "commonjs"
  }
}

We default the module option to commonjs here but you can override it in your tsconfig.json. Any chance that's happening? I suppose we could enforce it to commonjs in parcel.

Yeah, that's why I thought it was weird. After some investigation, the simple example code provided doesn't output any AMD wrapping at all unless require, export, etc. are used. @alexeypetrushin What's your typescript version? And is this the _only_ file in the entire project? No tsconfig or anything?

Hmm, I already killed the example, sorry don't have it anymore. I believe there were no tsconfig, just basic example without any config.

I have the same problem. I have tsconfig file. It works perfectly with the module:umd option but unfortunately does not work with amd. But I still need to compile with amd for my project and now I see only one solution to does not specify the module option in tsconfig file and add it directly during compilation: tsc --module amd. I use jasmine-ts for testing and it adds automatically module type commonjs if it is not specified in tsconfig. Maybe it will be useful for someone :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jsftw86 picture jsftw86  路  3Comments

466023746 picture 466023746  路  3Comments

Niggler picture Niggler  路  3Comments

donaldallen picture donaldallen  路  3Comments

philipodev picture philipodev  路  3Comments