I know this is require
/ import
ES6 thing. I have a project using import
and files are all .js
, based on this all I need is adding "type":"module"
into nearest package.json. This is my package.json at the same top level as server.js and env.js:
{
"name": "my project",
"version": "1.0.0",
"description": "many .js",
"main": "server.js",
"type":"module",
"directories": {
"test": "test"
},
"dependencies":{...},
"devDependencies":{...},
"scripts":{...},
"author":"John Doe"
}
server.js
import express from 'express';
import 'babel-polyfill';
import cors from 'cors';
import env from './env';
Still got
internal/process/esm_loader.js:74 internalBinding('errors').triggerUncaughtException( ^ Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'c:\project\env' imported from c:\project\server.js did you mean to import../env.js?
node is 14.9.0, using nvm.
launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}\\server.js"
}
]
}