I am facing an issue while trying to import a custom framework that I published on npmjs.org. I have created a .js file and a .d.ts file for this framework.
Initially, there are no errors during the import process until I compile the code. All the map links seem to work correctly and lead to the source when clicked with ctrl, and the types file is being detected.
The problem arises during compilation where any file importing these modules attempts to import them relative to its own path. Despite going through several questions on Stack Overflow and trying various suggestions, including using paths in the tsconfig file, the issue persists.
Error:
ERROR in ./src/scripts/game/mGameModel.ts 17:16-34
Module not found: Error: Can't resolve 'Scratch' in '/Users/derek/Projects/ghg/cash-mania/src/scripts/game'
The actual library files can be found at;
node_modules/@myorg/game-framework/dist/Scratch.js
node_modules/@myorg/game-framework/dist/Scratch.d.ts
node_modules/@myorg/game-framework/dist/Scratch.js.map
Could there be an issue with how I'm building the types file or what mistake might I be making?
Here is my tsconfig setup:
{
"compilerOptions": {
"target": "ES5",
"module": "commonjs",
"strict": true,
"noImplicitAny": false,
"esModuleInterop": true,
"allowUnreachableCode": false,
"experimentalDecorators": true,
"sourceMap": true,
"strictPropertyInitialization": false,
"typeRoots": [
"./node_modules/phaser/types",
"./node_modules/@myorg/game-framework/dist/"
],
"baseUrl": "./",
"types": [
"node",
"phaser"
],
...
I've tried adding paths in different ways and also included the folder in the 'include' section while ensuring the baseUrl is set correctly to ./
. However, the module always gets imported relative to the importing file's directory.
This is my webpack configuration:
...