#:rocket: Help Needed with TypeScript Module Errors(TS2306 & TS2305) :rocket:

14 messages ยท Page 1 of 1 (latest)

maiden sierra
#

Hey everyone! I'm working on a TypeScript project and have run into a series of compilation errors that I'm struggling to resolve. I've detailed the errors below and would greatly appreciate any insights or suggestions you might have!

Main Issues:

  1. Module Not Recognized: Some files (e.g., vue.shim.ts) are not being recognized as modules by TypeScript, leading to a TS2306 error.
  2. Exports Not Found: I'm frequently encountering the TS2305 error, where TypeScript can't find certain exports within my modules, such as Guid, GetResponseMessage, etc.

Error Examples:

  • TS2306: File '.../vue.shim.ts' is not a module.

  • TS2305: Module '.../_index' has no exported member 'Guid'.
    Attempts So Far:

  • Made sure all files intended to be modules include an export statement.

  • Checked the named exports for typos and correct export statements.

Questions:

  • How can I ensure TypeScript recognizes my .shim.ts and similar files as modules?
  • What's the best practice for organizing and exporting entities to avoid the TS2305 error?

I've tried reviewing my module structure and export/import statements, but the errors persist. Any advice on debugging these issues or resources you could point me toward would be super helpful!

Thank you in advance for your time and help! ๐Ÿ™

weary perch
#

How can I ensure TypeScript recognizes my .shim.ts and similar files as modules?
JS/TS has 2 main kinds of file

  • regular scripts
  • ES modules
    you can turn a regular script into an ES module by adding an export statement
#

but you might want to give us more info on what the content of that shim file is, and why you think it's a module, and why you think you need to import it

#

What's the best practice for organizing and exporting entities to avoid the TS2305 error?
no clue
what's TS2305 in the first place? (ppl usually don't refer to errors via their error code, just read the error message)

#

error TS2305: Module has no exported member
you have forced TS to consider all your files as ES modules, by using the moduleDetection option (or maybe isolatedModules)
but those files don't contain any export statement, so there is clearly something wrong going on with your code

#

๐Ÿ‘‰ but tbh, there is nothing specific to TS about those errors
ES modules are JS features
if you know JS and ES modules in JS, then there is nothing different when it comes to TS

#

@maiden sierra

maiden sierra
#

I see. Let me look into this.

#

Here's what shim file looks like:

fathom patrol
#

If you can attach code as codeblocks:

```ts
// code here

it's more helpful than a text file

maiden sierra
#

Here's the content of the shim file: ```ts
import Vue from "vue";
import { Guid } from "@fysb/core";

Vue.prototype.$polarOptions = [
{ id: 0, value: false, label: "No" },
{ id: 1, value: true, label: "Yes" }
];
Vue.prototype.$uuid = Guid;
Vue.prototype.$toJson = data => JSON.parse(JSON.stringify(data));
Vue.prototype.$isDev =
window.location.href.indexOf("localhost") >= 0 ||
window.location.href.indexOf("qa.") >= 0;

export default Vue;

#

And it's being imported here, where it's causing an error: ```ts
import "es6-promise/auto"; //Thanks IE
import EvaluationFormsCss from "../assets/EvaluationFormsCss";
import Vue from "../core/infrastructure/typings/vue.shim";
import BootstrapVue from "bootstrap-vue";
import EvaluationFormComponents from "@fysb/vue/evaluation-forms";

Vue.use(BootstrapVue);
Vue.prototype.$error = () => {
window.location.href = "/error";
};

new EvaluationFormsCss();
new Vue({
el: "#app",
components: EvaluationFormComponents
});

#

And here's the error: ERROR in C:\Users\khoku\source\repos-2\pmdms\FYSB.Web\app\boot\evaluation-forms.ts ./boot/evaluation-forms.ts [tsl] ERROR in C:\Users\khoku\source\repos-2\pmdms\FYSB.Web\app\boot\evaluation-forms.ts(3,17) TS2306: File 'C:\Users\khoku\source\repos-2\pmdms\FYSB.Web\app\core\infrastructure\typings\vue.shim.ts' is not a module.