I have created simple JS app(using npm init
) to achieve absolute path but facing an import issue.
My package.json
is like,
"name": "test-abs",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"dev": "nodemon src/index.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"nodemon": "^2.0.22"
},
"devDependencies": {
"basetag": "^2.1.0"
}
}
I have index.js
, test1.js
in src
folder
In /src/index.js
,
import { app1 } from "$/src/test1.js";
app1();
In test1.js
,
export const app1 = () => {
console.log("app1");
};
When I start npm run dev
server getting
(function (exports, require, module, __filename, __dirname) { import { app1 } from "$/src/test1.js";
^^^^^^
SyntaxError: Unexpected token import
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:617:28)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Function.Module.runMain (module.js:694:10)
at startup (bootstrap_node.js:204:16)
at bootstrap_node.js:625:3
My node is v16.18.0
Please let me know why I am facing this issue and how to fix this.