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

Module not found: Can't resolve 'tslib' when importing transformImageUrl #347

Closed
tommarshall opened this issue May 26, 2022 · 1 comment
Closed

Comments

@tommarshall
Copy link

tommarshall commented May 26, 2022

Brief bug description

Module not found: Can't resolve 'tslib' in './node_modules/@kentico/kontent-core/dist/es5/helpers'

When importing transformImageUrl from @kentico/kontent-delivery to build image transformation URLs, e.g. within a custom loader for Next/Image.

Repro steps

  1. Create a new Next.js project using cms-kontent example from the Next.js repo.
yarn create next-app --example https://github.com/vercel/next.js/tree/82a9d21/examples/cms-kontent tslib-import-error-demo
  1. Set up the project as per the Next.js example README instructions.
  2. Run yarn build to build the project.

Expected behaviour

The build should succeed.

Actual behaviour

The build fails with the following error:

$ next build
info  - Loaded env from /Users/tom/projects/tmp/.env.local
info  - Checking validity of types
warn  - No ESLint configuration detected. Run next lint to begin setup
info  - Creating an optimized production build
Failed to compile.

./node_modules/@kentico/kontent-core/dist/es5/helpers/enum.helper.js
Module not found: Can't resolve 'tslib' in '/Users/tom/projects/next-kontent-on-demand-isr-demo/node_modules/@kentico/kontent-core/dist/es5/helpers'

Import trace for requested module:
./node_modules/@kentico/kontent-core/dist/es5/helpers/index.js
./node_modules/@kentico/kontent-core/dist/es5/index.js
./node_modules/@kentico/kontent-delivery/dist/es6/client/delivery-client.js
./node_modules/@kentico/kontent-delivery/dist/es6/client/index.js
./node_modules/@kentico/kontent-delivery/dist/es6/index.js
./components/image.js
./components/avatar.js
./components/hero-post.js
./pages/index.js
...

Test environment

  • Platform/OS: [macOS]
  • Browser [N/A]
  • Version [12.3.1 (21E258) Monterey]

Additional context

Adding tslib as a dependency to the Next project (e.g. yarn add tslib) fixes the error.

tslib is present in the @kentico/kontent-delivery package-lock.json, but it's listed as a dev dependency.

Assuming transformImageUrl is part of the public API, which it appears to be as it's documented, then I think tslib needs to be moved from a dev dependency to a standard dependency.

That's a straightforward fix that I can open a PR for, but given the error is occurring within a module of kontent-core, I'm not sure whether the right place to do that is in @kentico/kontent-delivery or downstream in @kentico/kontent-core. Guidance would be appreciated here...

To date I think this has gone unnoticed as the majority of Kontent projects are likely importing other packages that depend on tslib, e.g. Kontent Starter Corporate - Next.js, which includes tslib as a dependency of eslint-config-next (via @typescript-eslint/parser -> @typescript-eslint/typescript-estree -> tsutils -> tslib)

@Enngage
Copy link
Member

Enngage commented May 27, 2022

Hi @tommarshall,

Thank you for the details and opening the issue here.

As far as I understand the tslib is just a runtime library for typescript and as such should not be part of the public API or be listed as a dependency of the project. I would assume that you would get similar error if you used something other than transformImageUrl, is that correct?

tslib is (or is not) needed depending on how your build process is set up. In your case the proper solution would just be to include it in your own devDependencies (again not dependencies because it's only needed for building your app) as you have already done ;)

@Enngage Enngage closed this as completed Jun 23, 2022
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