-
Notifications
You must be signed in to change notification settings - Fork 47
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
exports is not defined #202
Comments
EDIT: created repo https://github.com/aluanhaddad/plugin-text-plugin-typescript-issue-x For reference, I was able to reproduce the specific error encountered by @MoonStorm but becoming perplexed with trying to find the root cause, I tried a number of different scenarios, including issues which break usage when transpiling to supported formats. For my tests I used the following setup SystemJS: 0.20.10 Files index.html <!DOCTYPE html>
<html lang="en">
<body>
<script src="jspm_packages/system.js"></script>
<script src="jspm.config.js"></script>
<script>
SystemJS.import('app').then(app => app.default()).catch(console.error);
</script>
</body>
</html> src/main.ts import template from './template.html';
export default function () {
console.log(template);
} src/template.html <div>Hello</div> jspm.config.js (dependency config elided but standard) SystemJS.config({
paths: {
"github:": "jspm_packages/github/",
"npm:": "jspm_packages/npm/",
"app/": "src/"
},
transpiler: "plugin-typescript",
sourceMap: true,
typescriptOptions: {
"tsconfig": "tsconfig.{format}.json" // see below
},
packages: {
"app": {
"main": "main.ts",
"defaultExtension": "ts",
"meta": {
"*.ts": {
"loader": "plugin-typescript"
},
"*.html": {
"loader": "text"
}
}
}
}
}); tsconfig.es2015.json { "compilerOptions": { "module": "es2015", "target": "es5" } } tsconfig.system.json { "compilerOptions": { "module": "system", "target": "es5" } } tsconfig.amd.json { "compilerOptions": { "module": "amd", "target": "es5" } } tsconfig.commonjs.json { "compilerOptions": { "module": "commonjs", "target": "es5" } } Here were the unbundled results:
system
amd
commonjs
Here were the bundled results ( es2015
bundled template.html System.register("app/template.html", [], function (_export, _context) {
"use strict";
var __useDefault;
return {
setters: [],
execute: function () {
_export("__useDefault", __useDefault = true);
_export("__useDefault", __useDefault);
_export("default", "<div>Hello</div>");
}
};
}); system
bundled template.html System.register("app/template.html", [], function (_export, _context) {
"use strict";
return {
setters: [],
execute: function () {
System.register([], function (exports_1, context_1) {
"use strict";
var __moduleName = context_1 && context_1.id;
var __useDefault;
return {
setters: [],
execute: function () {
exports_1("__useDefault", __useDefault = true);
exports_1("default", "<div>Hello</div>");
}
};
});
}
};
}); amd
bundled template.html "bundle";
System.register("app/template.html", [], function (_export, _context) {
"use strict";
return {
setters: [],
execute: function () {
define(["require", "exports"], function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.__useDefault = true;
exports.default = "<div>Hello</div>";
});
}
};
}); commonjs
bundled template.html "use strict";
System.register("app/template.html", [], function (_export, _context) {
"use strict";
return {
setters: [],
execute: function () {
Object.defineProperty(exports, "__esModule", { value: true });
exports.__useDefault = true;
exports.default = "<div>Hello</div>";
}
};
}); On the one hand, the in browser workflow does not work correctly for any module format besides, I realize much of this is extraneous to the specific issue but I believe it may well be related as this could well be the result of metadata being set under the wrong circumstances. Also, some of these results are extremely strange, in particular, bundling under "system" should work. I know that this one has worked in the past and with plugin-text. |
Update Hopefully this information is helpful. |
Thank you for taking the time to do this, it is really appreciated and it would be great if we can get to the bottom of some of these interoperability issues. I have looked at the unbundled behaviour and here are my comments:
I have responded to the issue on the plugin-text repo. The problem is that plugin-text is outputting an amd module and in typescript to import the default export of an amd/commonjs module you need to use
Because typescript is not outputting system/es2015 modules it is essentially having to handle the module interop at compile time instead of systemjs handling it at runtime. The problem is compounded by the fact that plugin-text uses esm modules when bundled and amd for unbundled which makes it impossible I think. Regarding the plugin setting the module format in the metadata, that is code which I would really like to remove, but when I do things stop working. |
After posting this bug on several projects, I ended up posting it in here. I am trying to import HTML templates in typescript while using the text plugin. Typescript is set to generate
commonjs
modules and targetes5
and the text plugin produceses
modules. In this configuration, the bundle generated by thejspm bundle
looks like this:Using this bundle in the browser produces the error
exports is not defined
.Aligning the text plugin to generate
cjs
modulesfixes this problem and the bundle looks like this:
The issue has been discussed a little bit in here, with @guybedford and @aluanhaddad trying to get to the bottom of it.
Any help would be appreciated. Thanks.
The text was updated successfully, but these errors were encountered: