tensorflow / tfjs

A WebGL accelerated JavaScript library for training and deploying ML models.
https://js.tensorflow.org
Apache License 2.0
18.49k stars 1.93k forks source link

Next.js Cannot get final name for export 'transposeImplCPU' error #8235

Open FlyingTurkman opened 7 months ago

FlyingTurkman commented 7 months ago

I am trying to build a next js app includes tensorflow.js but an error has occured.

Creating an optimized production build ... Failed to compile.

./node_modules/@tensorflow/tfjs-backend-webgl/dist/register_all_kernels.js + 256 modules Cannot get final name for export 'transposeImplCPU' of ./node_modules/@tensorflow/tfjs-backend-webgl/dist/kernels/Transpose_impl.js

Build failed because of webpack errors

Tensorflow versions: "@tensorflow/tfjs": "^4.17.0", "@tensorflow/tfjs-core": "^4.17.0",

Code

import * as tf from '@tensorflow/tfjs'
import '@tensorflow/tfjs'
import '@tensorflow/tfjs-backend-webgl'

Also when I tried deploy to vercel same error occured.

gaikwadrahul8 commented 7 months ago

Hi, @FlyingTurkman

I apologize for the delayed response and thank you for bringing this issue to our attention, as far I know that error typically arises due to a Webpack configuration issue during the build process so may be Webpack's tree-shaking functionality might be causing problems. Try disabling it for the TensorFlow.js packages If you're comfortable with a potential increase in bundle size and want a quick solution, disabling tree-shaking globally might solve this issue and please refer official documentation of Generating size-optimized browser bundles with TensorFlow.js, if possible please give it try with Rollup might have better compatibility with TensorFlow.js:

// webpack.config.js
module.exports = {
  // ... other configurations
  optimization: {
    minimize: true,
    sideEffects: false, // Disable tree-shaking for TensorFlow.js packages
  },
};

If I have missed something here please let me know. Thank you for your cooperation and patience.

FlyingTurkman commented 7 months ago

Hi, @FlyingTurkman

I apologize for the delayed response and thank you for bringing this issue to our attention, as far I know that error typically arises due to a Webpack configuration issue during the build process so may be Webpack's tree-shaking functionality might be causing problems. Try disabling it for the TensorFlow.js packages If you're comfortable with a potential increase in bundle size and want a quick solution, disabling tree-shaking globally might solve this issue and please refer official documentation of Generating size-optimized browser bundles with TensorFlow.js, if possible please give it try with Rollup might have better compatibility with TensorFlow.js:

// webpack.config.js
module.exports = {
  // ... other configurations
  optimization: {
    minimize: true,
    sideEffects: false, // Disable tree-shaking for TensorFlow.js packages
  },
};

If I have missed something here please let me know. Thank you for your cooperation and patience.

Thank you for response but not working.