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

Error loading uuid_ossp extensions #453

Open
sergio-milu opened this issue Dec 2, 2024 · 3 comments
Open

Error loading uuid_ossp extensions #453

sergio-milu opened this issue Dec 2, 2024 · 3 comments

Comments

@sergio-milu
Copy link

sergio-milu commented Dec 2, 2024

Hey,

Version: @electric-sql/pglite": "^0.2.14

I'm trying to setup PGLite in my typeorm project for testing. I'm using jest + SWC. The error that I'm getting is

({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){import { d as PGliteInterface } from '../pglite-CCwqaSmq.js';
                                                                                      ^^^^^^

SyntaxError: Cannot use import statement outside a module

The setup

import * as uuid_ossp from '@electric-sql/pglite/dist/contrib/uuid_ossp';
import { TypeOrmModule } from '@nestjs/typeorm';
import { PGliteDriver } from 'typeorm-pglite';

console.log(uuid_ossp);

export const getRootTypeormModule = () => {
  return TypeOrmModule.forRoot({
    type: 'postgres',
    driver: new PGliteDriver({ extensions: { uuid_ossp: uuid_ossp.uuid_ossp } })
      .driver,
  });
};

This is my tsconfig

const config = {
  displayName: 'backend',
  restoreMocks: true,
  clearMocks: true,
  resetMocks: true,
  testEnvironment: 'node',
  preset: '../../jest.preset.js',
  globalSetup: '<rootDir>/jest.global-setup.ts',
  setupFiles: [
    'jest-plugin-unhandled-promise/setup',
    '<rootDir>/jest.setup.ts',
  ],
  transform: {
    '^.+\\.spec\\.[tj]s?$': '@swc/jest',
  },
  moduleFileExtensions: ['ts', 'js', 'html'],
  roots: ['<rootDir>', './src/__mocks__'],
  workerIdleMemoryLimit: 0.2,
  setupFilesAfterEnv: ['../../jest.setup-after-env.ts'],
};

SWC config

{
  "$schema": "http://json.schemastore.org/swcrc",
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "decorators": true,
      "dynamicImport": true
    },
    "transform": { "decoratorMetadata": true, "legacyDecorator": true },
    "loose": false
  }
}

Dont know why I need to import the uuid extensions from /dist (this is not what's shown in the docs)

Also, I tried to add this to jest config

transformIgnorePatterns: [`node_modules/(?!(@electric-sql/pglite)/)`]

and that error goes away but the import is an empty object

seems kind of an issue of ESmodule , but after a long time I didn't find the issue and not sure if it's up to me or some misconfiguration in the packages.

Any clue?

Thanks in advance

@copiltembel
Copy link
Contributor

There are some uuid_ossp tests in packages/pglite/tests/contrib/uuid_ossp.test.js. Does that help?

@MrKernelPanic-dev
Copy link

Hello,

I’m encountering the same issue as described earlier. Specifically, I’m trying to import uuid_ossp, and the problem seems to originate from @electric-sql/pglite/dist/contrib/uuid_ossp.d.ts. Here are the details:

Primary Issue

When attempting to import uuid_ossp, I get the following error:

  ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){import { d as PGliteInterface } from '../pglite-CCwqaSmq.js';
                                                                                    ^^^^^^

  SyntaxError: Cannot use import statement outside a module

Attempted Fix

I tried adding the following configuration in my Jest setup:

transformIgnorePatterns: ['node_modules/(?!(@electric-sql/pglite)/)']

However, this resulted in a new error:

TypeError: Cannot read properties of undefined (reading 'setup')

Reproduction Steps

I also attempted to reproduce the issue using the test examples in the pglite repository, specifically in packages/pglite/tests/contrib/uuid_ossp.test.js. I replaced the import with the following:

import { uuid_ossp } from '../../dist/contrib/uuid_ossp.d.ts';

This yielded the same undefined error.

Environment:

  • pglite Version: 0.2.14
  • ts-jest Version : 29.1.1
  • jest Version : 29.7.0

Thank you for investigating this issue. Please let me know if you need more details!

@sergio-milu
Copy link
Author

Hello,

I’m encountering the same issue as described earlier. Specifically, I’m trying to import uuid_ossp, and the problem seems to originate from @electric-sql/pglite/dist/contrib/uuid_ossp.d.ts. Here are the details:

Primary Issue

When attempting to import uuid_ossp, I get the following error:

  ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){import { d as PGliteInterface } from '../pglite-CCwqaSmq.js';
                                                                                    ^^^^^^

  SyntaxError: Cannot use import statement outside a module

Attempted Fix

I tried adding the following configuration in my Jest setup:

transformIgnorePatterns: ['node_modules/(?!(@electric-sql/pglite)/)']

However, this resulted in a new error:

TypeError: Cannot read properties of undefined (reading 'setup')

Reproduction Steps

I also attempted to reproduce the issue using the test examples in the pglite repository, specifically in packages/pglite/tests/contrib/uuid_ossp.test.js. I replaced the import with the following:

import { uuid_ossp } from '../../dist/contrib/uuid_ossp.d.ts';

This yielded the same undefined error.

Environment:

  • pglite Version: 0.2.14
  • ts-jest Version : 29.1.1
  • jest Version : 29.7.0

Thank you for investigating this issue. Please let me know if you need more details!

manage to know what's going on

you must import from @electric-sql/pglite/contrib/uuid_ossp.d.ts not the dist, event if TS complains about not exists, in my case this is cause my repo is not configured for modules yet, and you need to have that in order to be able to understand the exports in the package.json of this project

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

3 participants