Skip to content

Module not found: ESM packages (pocketbase) need to be imported. Use 'import' to reference the package instead. #76

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

Closed
nimamahmoudi opened this issue Nov 13, 2022 · 4 comments

Comments

@nimamahmoudi
Copy link

Hi, I'm getting this error, similar to #34 and #52 but the fixes there didn't work for me. I am fairly new to TypeScript and this is probably a mistake on my side, but would appreciate it if you could help me resolve it. Here are my configurations:

package.json:

{
  ...
  "type": "module",
}

tsconfig.json:

{
  "compilerOptions": {
    "target": "esnext",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": false,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "nodenext",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true
  },
  "include": [
    "next-env.d.ts",
    "**/*.ts",
    "**/*.tsx"
  ],
  "exclude": [
    "node_modules"
  ]
}
@ganigeorgiev
Copy link
Member

ganigeorgiev commented Nov 13, 2022

I'm not sure how to reproduce it. Could you provide a little more information on your setup (node and TS version, how do you load the SDK, etc.) or minimal reproducible repo?

The PocketBase JS SDK is ES module. The above error indicates that you are probably using require() instead of import. If you are using the CommonJS syntax, you'll have to use the cjs bundle, aka. const PocketBase = require("pocketbase/cjs").

@nimamahmoudi
Copy link
Author

Thank you for your response, I was using the import statement as indicated on the docs, but I was still getting the same error, which was strange. I ended up falling back to the common js module and using that one instead.

@ganigeorgiev
Copy link
Member

@nimamahmoudi Based only on the tsconfig.json it seems that you should be able to load ES modules but there also other factors, like the TS version you are using (TS esm support was added in v4.7!), whether there is another transpiler mixed, rollup/webpack plugin(s), etc.

If you decide later to give ES modules another try, feel free to comment/open another issue (ideally with a minimal reproducable repo) and I'll try to investigate it more thoroughly.

@nimamahmoudi
Copy link
Author

Found the issue while trying to set that repo up, thanks! The issue was that in that file I had the following:

import ....
...
module.exports = {
 ....
}

And apparently I can't use module.exports in the same file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants