-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Undefined "exports" when nothing is exported #15795
Comments
but the file is a module? how are you using this file? |
This file is not a npm module. It is loaded in browser on page load. |
|
Require has nothing to do with this problem. If I delete the line with "exports" manually after compilation everything works. I am using typescript version 2.1.4. Which still works for me and does not produce "exports", when there is no module exported. We do not use webpack or any other module bundler. We have an existing electron project, which compiles with: "scripts": {
"compile": "tsc -p .",
"watch-ts": "tsc -p . --watch",
} {
"compilerOptions": {
"target": "es2015",
"module": "commonjs",
"sourceMap": true,
"removeComments": false,
"moduleResolution": "node",
"jsx": "react",
"pretty": true,
"outDir": "assemble/"
},
"include": [
"client/**/*"
],
"exclude": [
"node_modules"
]
} |
Ah, Electron provides I am not sure what Mohamed's take on it will be, but this seems to fall into one person's regression is another person's feature. You are clearly instructing TypeScript to generate CommonJS modules. It is ensuring that it is emitting a module that fully complies with what is expected for a down-emitted CommonJS module so that loaders can differentiate on how to load it. Therefore because it is expecting to load by a CommonJS loader (like Node.js's |
@kitsonk we have the node integration turned on. You are right Typescript uses commonjs for module resolution. What I do not get is, why would you expect that "exports" is defined, when you are not specifing a module, just importing stuff. |
Just importing means it is a module. Whenever TypeScript sees the |
Hmm I see that typescript expects exports as variable in such an environment. But with e.g. "module":"amd" it also checks for existence of module.exports, but then accesses exports. While nwjs defines module.exports it does not define exports. I guess electron behaves similar.
Just checking for typeof exports === "object" too, would help. So the solution for "commonjs" should be to check if exports exists or using module.exports instead. |
I am now using a workaround: |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
TypeScript Version: typescript@2.3.2
Code
Expected behavior:
Actual behavior:
This is a recurrnig issue. #14351
I reported this previously.
After compilation appears
and the result is "Uncaught ReferenceError: exports is not defined.
Ther is no actual module exported in the file. If I manually remove this piece of code everything works fine.
The text was updated successfully, but these errors were encountered: