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

SSR build not work #72

Open
Farnsi opened this issue Jan 19, 2023 · 3 comments
Open

SSR build not work #72

Farnsi opened this issue Jan 19, 2023 · 3 comments

Comments

@Farnsi
Copy link

Farnsi commented Jan 19, 2023

I build my app without an error, but when run it with node command, it shows:

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

Node.js v18.13.0
fastify v4.11.0

vite.config

export default defineConfig({
  build: {
    emptyOutDir: true,
    outDir: './dist',
    sourcemap: true,
  },
  plugins: [
    ...VitePluginNode({
      adapter: 'fastify',
      appPath: './src/index.ts',
      exportName: 'viteNodeApp',
    }),
  ],
  ssr: {
    format: 'cjs',
  }
})

Here are all the places in the compiled index.js where the var buffer$1 is used:

var buffer$1 = {};
.
.
.
/*!
 * The buffer module from node.js, for the browser.
 *
 * @author   Feross Aboukhadijeh <https://feross.org>
 * @license  MIT
 */
(function(exports2) {
.
.
.
})(buffer$1);
.
.
.
const buffer = buffer$1;
const assert$4 = require$$0$6;
const kImpl = Symbol("kImpl");
const MAX_STRING = buffer.constants.MAX_STRING_LENGTH;
class FakeWeakRef {
  constructor(value) {
    this._value = value;
  }

buffer$1 contains:

{
  Buffer: [Function: Buffer2] {
    TYPED_ARRAY_SUPPORT: true,
    poolSize: 8192,
    from: [Function (anonymous)],
    alloc: [Function (anonymous)],
    allocUnsafe: [Function (anonymous)],
    allocUnsafeSlow: [Function (anonymous)],
    isBuffer: [Function: isBuffer],
    compare: [Function: compare2],
    isEncoding: [Function: isEncoding],
    concat: [Function: concat],
    byteLength: [Function: byteLength2]
  },
  SlowBuffer: [Function: SlowBuffer],
  INSPECT_MAX_BYTES: 50,
  kMaxLength: 2147483647
}

I really don't have an idea what causes that problem: node, a module, vite, vite-plugin-node, did you have any suggestion?

@axe-me
Copy link
Owner

axe-me commented Feb 3, 2023

can you make a repro or just paste the code snippet that using buffer.

@qeleb
Copy link

qeleb commented Feb 3, 2023

i had this same problem when outputting as CommonJS

@qeleb
Copy link

qeleb commented Feb 3, 2023

the debugger seemed to suggest this issue is in Vite but I’m not sure either

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