Rich-Harris/estree-walker

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in... error

samwightt opened this issue ยท 12 comments

Getting an error when I try to use estree-walker with esbuild:

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /Users/sam/Nine/components/node_modules/estree-walker/package.json
    at throwExportsNotFound (internal/modules/esm/resolve.js:290:9)
    at packageExportsResolve (internal/modules/esm/resolve.js:479:7)
    at resolveExports (internal/modules/cjs/loader.js:432:36)
    at Function.Module._findPath (internal/modules/cjs/loader.js:472:31)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:867:27)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (/Users/sam/Nine/components/dist/src/main.js:43:39)
    at Module._compile (internal/modules/cjs/loader.js:1063:30) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

Node Version: v14.15.4

tsconfig.json:

{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "allowJs": true,
    "importHelpers": true,
    "alwaysStrict": true,
    "sourceMap": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noImplicitAny": false,
    "noImplicitThis": false,
    "strictNullChecks": false
  },
  "include": ["src/**/*", "__tests__/**/*"]
}

I get the exact same issue, seems like it is nothing to do with esbuild:

$ npm i estree-walker

up to date, audited 268 packages in 4s

37 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

 $ node
Welcome to Node.js v14.5.0.
Type ".help" for more information.
> require('estree-walker')
Uncaught:
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main resolved in /Users/me/myproject/node_modules/estree-walker/package.json
    at resolveExportsTarget (internal/modules/cjs/loader.js:603:11)
    at applyExports (internal/modules/cjs/loader.js:461:14)
    at resolveExports (internal/modules/cjs/loader.js:514:23)
    at Function.Module._findPath (internal/modules/cjs/loader.js:642:31)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1017:27)
    at Function.Module._load (internal/modules/cjs/loader.js:899:27)
    at Module.require (internal/modules/cjs/loader.js:1090:19)
    at require (internal/modules/cjs/helpers.js:75:18)
    at repl:1:1
    at Script.runInThisContext (vm.js:131:18) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

Downgrading to 2.0.2 fixes it, and there don't appear to have been any code changes between 2.0.2 and 3.0.0 - just packaging changes so I guess those broke it somehow.

Same error in my environment!

Same here.

I guess this package is not planned to be used in a CommonJS module anymore. It's written as a ES Module and published directly from the src, so it's necessary to use "type": "module" in package.json and convert your package to esm or use a custom resolver.

To test it in the cli:

import('estree-walker').then((m) => console.log(m))

The only thing I found weird is that there's still a "package.json" file under the "src" folder published. You'll only see this by installing the package and inspecting the node_modules since it's not in the repo and is not generated by the build process. I guess it was a left over in the pc of the person who published the last version, since there's no cleaning script pre-publish. This broke my ESLint module resolution for the import/export plugin and removing that file solved it.

binvb commented

same here, any progress? version@2.0.2 is fine๏ผŒthank you

Same issue using TSX and MDX.

v3.0.1 - same problem. Can we get an es and cjs build plz?

This has been going on since 21st Feb 2021. Ill fork the repo and fix it.

This is an ESM only package now. But it's still possible to use it from CJS: You will have to use dynamic imports like this:

const { walk } = await import("estree-walker");
walk(...);

The usage example on README.md doesn't work at all. At least update the readme if you are dropping cjs support.