Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not able use in node 15 with type: module in package.json #116

Open
sandeshfromindia opened this issue Mar 11, 2021 · 3 comments
Open

not able use in node 15 with type: module in package.json #116

sandeshfromindia opened this issue Mar 11, 2021 · 3 comments

Comments

@sandeshfromindia
Copy link

Hi, I am trying to use module-alias in my project and I am using node js 15.x type: module in package.json but it not working for me. see below code snippets.

package.json

{
"name": "alias-test",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"test": "echo "Error: no test specified" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"module-alias": "^2.2.2"
},
"type": "module",
"_moduleAliases" : {
"@root" : ".",
"@con" : "./config"
}
}

server.js

require('module-alias/register');

import '@con/module';

module.js
console.log("from Module Config");

getting error :

node:internal/process/esm_loader:74
internalBinding('errors').triggerUncaughtException(
^

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@con/module' imported from D:\projects\Node\alias-test\server.js
?[90m at new NodeError (node:internal/errors:278:15)?[39m
?[90m at packageResolve (node:internal/modules/esm/resolve:698:9)?[39m
?[90m at moduleResolve (node:internal/modules/esm/resolve:739:18)?[39m
?[90m at Loader.defaultResolve [as _resolve] (node:internal/modules/esm/resolve:853:11)?[39m
?[90m at Loader.resolve (node:internal/modules/esm/loader:86:40)?[39m
?[90m at Loader.getModuleJob (node:internal/modules/esm/loader:230:28)?[39m
?[90m at ModuleWrap. (node:internal/modules/esm/module_job:56:40)?[39m
?[90m at link (node:internal/modules/esm/module_job:55:36)?[39m {
code: ?[32m'ERR_MODULE_NOT_FOUND'?[39m

@richardeschloss
Copy link

Related? #59

@c-DiRay
Copy link

c-DiRay commented Mar 23, 2021

You can use node's native "imports" field, but it is less flexible then this module
nodejs.org/api

package.json

{
  "imports":{
    "#root/*": "./*",
    "#con":    "./config.json"
  }
}

@its-dibo
Copy link

You can use node's native "imports" field, but it is less flexible then this module nodejs.org/api

package.json

{
  "imports":{
    "#root/*": "./*",
    "#con":    "./config.json"
  }
}

it forces you to rewrite all of your path aliases to be stat with '#'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants