简体   繁体   中英

Why babel-node "Cannot find module" without ".js" extension?

I dont know why babel-node does not import without ".js" extension.

  • I have "type": "module" in package.js
  • import example from "./src/example.js"; works fine
  • import example from "./src/example"; doesnt work
  • --es-module-specifier-resolution=node works only when I dont use babel-node

package.js

    "type": "module",
    "scripts": {
        "start": "node  ./index.js --exec babel-node -e js --experimental-modules --es-module-specifier-resolution=node "
    },
    "dependencies": {
        "bcrypt": "^5.0.1",
        "body-parser": "^1.20.0",
        "express": "^4.18.1",
        "jsonwebtoken": "^8.5.1",
        "mongoose": "^6.3.5",
        "nodemon": "^2.0.16",
        "npm": "^8.12.1"
    },
    "devDependencies": {
        "@babel/cli": "^7.17.10",
        "babel-preset-env": "^1.7.0",
        "babel-preset-stage-0": "^6.24.1"
    }

npm install @babel/node解决了我的问题

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM