You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Try to register the Core as an alias dynamically, in the App.js file:
import * as path from "path"
import * as url from "url"
const __filename = url.fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
import moduleAlias from "module-alias"
const corePath = path.join(__dirname, "Core")
moduleAlias.addPath("/")
console.log(corePath)
moduleAlias.addAlias("Core", corePath)
import "module-alias/register.js"
import { camelize } from "Core"
console.log(camelize("Hello"))
You get this error:
node:internal/modules/esm/resolve:854
throw new ERR_MODULE_NOT_FOUND(packageName, fileURLToPath(base), null);
^
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'Core' imported from /HolismHolding/Generation/Generate.js
at packageResolve (node:internal/modules/esm/resolve:854:9)
at moduleResolve (node:internal/modules/esm/resolve:927:18)
at defaultResolve (node:internal/modules/esm/resolve:1169:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:542:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:510:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:239:38)
at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:96:40)
at link (node:internal/modules/esm/module_job:95:36) {
code: 'ERR_MODULE_NOT_FOUND'
}
Node.js v20.18.1
This is a simple example. I'm trying to alias a lot of directories. I want to be able to write these imports:
import { camelize } from "Core"
import { getPosts } from "Blog"
import { createProduct } from "Products"
...
And each Core or Blog or ... is in a nested directory and they are dynamically added or removed (a CMS).
But even a simple setup as the above does not work.
What should I do?
The text was updated successfully, but these errors were encountered:
Consider this structure:
Try to register the
Core
as an alias dynamically, in theApp.js
file:You get this error:
This is a simple example. I'm trying to alias a lot of directories. I want to be able to write these imports:
And each
Core
orBlog
or ... is in a nested directory and they are dynamically added or removed (a CMS).But even a simple setup as the above does not work.
What should I do?
The text was updated successfully, but these errors were encountered: