Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

self is not defined #164

Closed
globalexport opened this issue Apr 8, 2024 · 2 comments · Fixed by #178
Closed

self is not defined #164

globalexport opened this issue Apr 8, 2024 · 2 comments · Fixed by #178
Assignees
Labels
bug Something isn't working

Comments

@globalexport
Copy link

ReferenceError [Error]: self is not defined
      at Object.<anonymous> (/Users/me/projects/project/dev-repo/repos/some-api/node_modules/.pnpm/i18n-postal-address@0.9.1/node_modules/i18n-postal-address/dist/postal-address.js:1:208)
      at Module._compile (node:internal/modules/cjs/loader:1376:14)
      at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
      at Module.load (node:internal/modules/cjs/loader:1207:32)
      at Module._load (node:internal/modules/cjs/loader:1023:12)
      at cjsLoader (node:internal/modules/esm/translators:356:17)
      at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:305:7)
      at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
      at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
      at async importModuleDynamicallyWrapper (node:internal/vm/module:431:15)

Node v20,
ESM import
Package version v0.9.1

Causative code:

import PostalAddress from 'i18n-postal-address'

Indeed, self does not look defined in the named dist file.

Bildschirmfoto 2024-04-08 um 17 19 43

Is it a bundling bug?

@globalexport
Copy link
Author

The error can be avoided with this piece of code before importing.

  if (typeof self === 'undefined' && typeof global === 'object') {
    global.self = global
  }

@joaocarmo joaocarmo self-assigned this May 12, 2024
@joaocarmo joaocarmo added the question Further information is requested label May 12, 2024
@joaocarmo
Copy link
Owner

I can replicate this on a new project with:

  1. pnpm init
  2. add "type": "module" to package.json
  3. use import PostalAddress from 'i18n-postal-address'

I think this can be fixed by specifying exports with package.json:exports for ESM.

@joaocarmo joaocarmo added bug Something isn't working and removed question Further information is requested labels May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants