Answer the question
In order to leave comments, you need to log in
How to fix index.js:2 Uncaught ReferenceError: exports is not defined?
How to fix index.js:2 Uncaught ReferenceError: exports is not defined ?
Answer the question
In order to leave comments, you need to log in
You probably compiled your TS to CommonJS and tried to open the resulting files in a browser.
It won't work, the browser doesn't know anything about the Node.js module system (from here exports is not defined
).
Offhand, 2 ways to solve the problem:
1) build a bundle (look towards webpack, rollup, parcel)
2) change module to es2015 or esnext in tsconfig so as not to transform modules (for example, study this )
Oh my god... I spent about two hours trying to solve it. And I really want to help somebody. The following works for me:
install:
@babel/plugin-transform-runtime
next step:
.babelrc
{
"presets": [
[
"@babel/preset-env",
{
"useBuiltIns": "usage",
"corejs": 3
}
]
],
"plugins": ["@babel/plugin-transform-runtime"]
}
"target": "ES5",
"module": "CommonJS",
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question