0

I'm trying to use declare with WebPack, but instead of leaving the variable names alone, it adds _script_project__WEBPACK_IMPORTED_MODULE_0__ in front of it during compilation. This causes the variables to be undefined. Does anyone know how to solve this? Thank you!

project.ts

export declare namespace Module
{
    class Project{
        constructor()
    }
}

index.ts

import { Module } from "./script/project"

const project = new Module.Project()
alert(project)

UPDATE

Well, I figured it out. Webpack creates an object for each module which contains the exported variables even if you use the declare keyword. This means that in other modules these variables will get _script_project__WEBPACK_IMPORTED_MODULE_X__ in front of it. You can fix this by removing export or by using global scope through the global variable.

JMRC
  • 1,473
  • 1
  • 17
  • 36
  • Did the person who closed my question even read it? Without Webpack this error doesn't even occur. It's like giving an apple pie recipe, while I asked for a lasagna recipe because they both happened to involve an oven. – JMRC Mar 20 '23 at 06:40

0 Answers0