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

cannot import to esm project #13

Open
iambumblehead opened this issue Jan 11, 2023 · 2 comments
Open

cannot import to esm project #13

iambumblehead opened this issue Jan 11, 2023 · 2 comments

Comments

@iambumblehead
Copy link

Describe the bug

import apollo-server-logging into an esm project causes a runtime error (node v19.2.0 here)

(node:16428) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
/Users/user/software/app/node_modules/apollo-server-logging/dist/esm/index.js:1
export * from './plugin.js';
^^^^^^

SyntaxError: Unexpected token 'export'
    at internalCompileFunction (node:internal/vm:74:18)
    at wrapSafe (node:internal/modules/cjs/loader:1141:20)
    at Module._compile (node:internal/modules/cjs/loader:1182:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1272:10)
    at Module.load (node:internal/modules/cjs/loader:1081:32)
    at Module._load (node:internal/modules/cjs/loader:922:12)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)

To Reproduce
Steps to reproduce the behavior:

  1. import the package into your project 'import ApolloServerLogging from 'apollo-server-logging';'
  2. run your project

Desktop (please complete the following information):

macos, node v19.2.0

@iambumblehead
Copy link
Author

also a few little adjustments for the README

+import ApolloServerLogging from 'apollo-server-logging';
import { ApolloServer } from 'apollo-server'
import { schema } from './schema'
import { logger } from './logger'

export const server = new ApolloServer({
  schema,
  plugins: [
    ApolloServerLogging({
      // Pass in your application logger here, or leave blank to use the
      // default `pino()` logger.
-     logger
+     logger,
      // All parameters are logged, so use this option to redact certain
      // sensitive information from your logs:
-     cleanVariableNames: ['password', 'token', 'phone', 'email'],
+     cleanVariableNames: ['password', 'token', 'phone', 'email']
      // By default, the above setting's value is `['password', 'token', 'captcha']`
-   }),
+   })
  ]
})

@iambumblehead
Copy link
Author

I'm able to import this package when the following changes are made.

Add the following to apollo-server-logging's package.json exports,

  "exports": {
    ".": {
      "types": "./dist/types/index.d.ts",
      "import": "./dist/esm/index.js",
      "require": "./dist/cjs/index.js"
    },
+   "./cjs": "./dist/cjs/index.js",
    "./*": {
      "types": "./dist/types/*.d.ts",
      "import": "./dist/esm/*.js",
      "require": "./dist/cjs/*.js"
    }
  },

Import apollo-server-logging in the following way from the dependent project

import { ApolloLoggerPlugin as ApolloServerLogging } from 'apollo-server-logging/cjs';

if you would export the cjs that would help me to use this package.

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

1 participant