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

[BUG] #1617

Open
6 tasks done
paragmightybear opened this issue Jul 14, 2023 · 1 comment
Open
6 tasks done

[BUG] #1617

paragmightybear opened this issue Jul 14, 2023 · 1 comment

Comments

@paragmightybear
Copy link

Summary:

Get this critical error when building a Dynamoose project with a Next.JS Typescript project.

./node_modules/dynamoose/dist/utils/importPackage.js
Critical dependency: the request of a dependency is an expression

Import trace for requested module:
./node_modules/dynamoose/dist/utils/importPackage.js
./node_modules/dynamoose/dist/utils/index.js
./node_modules/dynamoose/dist/index.js
...

Code sample:

Schema

export const PlayerProfileSchema = new Schema({
	"player-id": {
		type: String,
		hashKey: true,
	},
	"email-address": {
		type: String,
	},
	"profile-pic-url": {
		type: String,
		required: false,
	},
	"accept-tos-time": {
		type: Number,
	},
	"accepts-marketing": {
		type: Boolean,
		default: false,
	},
	"last-updated": {
		type: Number,
		required: true,
	},
});

Model

export const PlayerProfile = model(playerProfilesTableName, PlayerProfileSchema, {
	create: false,
});

General

While this dosesn't cause any runtime issues, it still throws a critical dependency warning at build time

Current output and behavior (including stack trace):

./node_modules/dynamoose/dist/utils/importPackage.js
Critical dependency: the request of a dependency is an expression

Import trace for requested module:
./node_modules/dynamoose/dist/utils/importPackage.js
./node_modules/dynamoose/dist/utils/index.js
./node_modules/dynamoose/dist/index.js
...

Expected output and behavior:

No errors on building a next project

Environment:

Operating System: MacOS
Operating System Version: Ventura 13.1
Node.js version (node -v): v20.2.0
NPM version: (npm -v): 9.6.6
Dynamoose version: 3.2.0

Other information (if applicable):

Other:

  • I have read through the Dynamoose documentation before posting this issue
  • I have searched through the GitHub issues (including closed issues) and pull requests to ensure this issue has not already been raised before
  • I have searched the internet and Stack Overflow to ensure this issue hasn't been raised or answered before
  • I have tested the code provided and am confident it doesn't work as intended
  • I have filled out all fields above
  • I am running the latest version of Dynamoose
@zetorama
Copy link

It seems to be related to how dynamoose imports dynamoose-logger via non-static require(name) call, and because Next.js uses webpack (which requires static imports to bundle the code), the error comes from it.

This is what helped me to resolve the issue – adding it to serverComponentsExternalPackages in the next.config.js:

/** @type {import('next').NextConfig} */
const config = {
  ...
  experimental: {
    // Next.js is getting issues trying to compile dynamoose, so need to opt-out it from bundling
    serverComponentsExternalPackages: ['dynamoose'],
  },
};

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

No branches or pull requests

2 participants