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

node-rs/jieba 与nextjs13整合出现了问题 #684

Closed
hevi1991 opened this issue Jun 2, 2023 · 0 comments
Closed

node-rs/jieba 与nextjs13整合出现了问题 #684

hevi1991 opened this issue Jun 2, 2023 · 0 comments

Comments

@hevi1991
Copy link

hevi1991 commented Jun 2, 2023

大概是与nextjs13的webpack打包后node文件地址错误导致的.

如果不使用node-load, 会报如下错误

Failed to compile
./node_modules/@node-rs/jieba-win32-x64-msvc/jieba.win32-x64-msvc.node
Module parse failed: Unexpected character '�' (1:2)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)

如果使用native-ext-loader去加载node文件, 并改写了地址. 开发运行模式npm run dev会报错误. #628 . 且打包生产环境后, 依然有__dirname 导致的找不到 node 文件的错误.

// next.config.js 

const path = require("path");

/** @type {import('next').NextConfig} */
const nextConfig = {
  webpack: (config, context) => {
    // console.log(`-------------------------------------------------->>>>`);
    console.log(`context.isServer ${context.isServer}`);
    config.module.rules = [
      ...config.module.rules,
      {
        test: /\.node$/,
        loader: "native-ext-loader",
        options: {
          rewritePath: path.resolve(__dirname, ".next/server"),
        },
      },
    ];
    // console.log(`--------------------------------------------------<<<<`);
    return config;
  },
};

module.exports = nextConfig;

能否将不同平台的node文件都整合到一个包中, 改写一下引用规则. 或者有更好的办法.

:-c 求助大佬

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