adraffy / ens-normalize.js

ENSIP-15 in JS
https://adraffy.github.io/ens-normalize.js/test/resolver.html
MIT License
67 stars 17 forks source link

Typescript Node import not supported #7

Closed wjram2133 closed 1 year ago

wjram2133 commented 2 years ago

Error emits: Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /home/.../node_modules/@adraffy/ens-normalize/dist/index.js require() of ES modules is not supported.

with configuration: { "compileOnSave": true, "allowJs": true, "compilerOptions": { "module": "commonjs", "esModuleInterop": true, "target": "es6", "noImplicitAny": false, "sourceMap": true, "baseUrl": ".", "rootDir": ".", "allowJs": true, "skipLibCheck": true, "moduleResolution": "node", "experimentalDecorators": true, "importHelpers": true, "resolveJsonModule": true, "allowSyntheticDefaultImports": true, "typeRoots": [".node_modules/@types"], "outDir": "./dist", "paths": { "src": ["./src"] } }, "ts-node": { "require": ["tsconfig-paths/register"] }, "include": ["./**/*"], "exclude": ["./node_modules/**/*"], "allowSyntheticDefaultImports": true }

adraffy commented 2 years ago

You'll have to give me more information. Are you using require()?

mkeresty commented 1 year ago

I am having the same issue in production. I have tried both import and require. Works fine locally.

adraffy commented 1 year ago

I see that I'm missing "types" in my package.json but I don't see anything else that would prevent a bundler from including dist/index.js — it's simply a 0 dependency ES6 module.

AFAICT, TS by default uses CommonJS w/o node resolution. The issue appears to be that TS is blindly emitting require('@adraffy/ens-normalize'). If I make a new TS project, and set my tsconfig to ..., module: "es6", moduleResolution: "node", ..., I get the expected compiled output.

I'm not a JS dev so any advice would be appreciated. I'm under the impression that supplying a CommonJS prebuild is unnecessary.

adraffy commented 1 year ago

I have included a CJS build and updated the npm package accordingly (1.8.8). Hopefully, this should improve import/require experience.