I'm creating my first app using TypeScript. I'm trying to import a class that I've created in a seperate .ts file that is at the root level with main.ts. I've tried using both of the following to import the file in main.ts...
import * as myclass from './myclass';
const myclass = require( './myclass ' );
When I activate a flow with my app, I get an error message that my class module can't be found as it's being looked for in the node_modules directory instead of in the root directory.
Cannot find module '<path to my app>\node_modules\myclass' Require stack: - C:\Program Files\Enfocus\Enfocus Switch\ScriptExecutor\NodeScriptExecutor.js
What is the proper way to include my own modules?
importing/require myclass.ts module
Re: importing/require myclass.ts module
Is this for an app or for a local script?
If it is for a local script, use the complete path to the file instead of a relative path.
If it is for an app or for another situation in which the usage of a complete path is not possible or desirable, you will have to make sure that your own module ends up in node_modules. The way to do that is to create that module in some other location away from your script. Make sure it is a folder with a package.json file that is correctly configured (npm init) and then in the script folder you do an npm install of the folder with your module.
Note that this takes a snapshot of your own module into the node_modules folder of the script, so if you make changes to the module you have to npm install it again.
If it is for a local script, use the complete path to the file instead of a relative path.
If it is for an app or for another situation in which the usage of a complete path is not possible or desirable, you will have to make sure that your own module ends up in node_modules. The way to do that is to create that module in some other location away from your script. Make sure it is a folder with a package.json file that is correctly configured (npm init) and then in the script folder you do an npm install of the folder with your module.
Note that this takes a snapshot of your own module into the node_modules folder of the script, so if you make changes to the module you have to npm install it again.