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

pnpm workspace monorepo方式导出报错 You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file #15955

Open
DreamPWJ opened this issue Jun 21, 2024 · 13 comments
Labels
F-vue3 Framework - Vue 3 V-3 Version - 3.x

Comments

@DreamPWJ
Copy link

DreamPWJ commented Jun 21, 2024

相关平台

微信小程序

小程序基础库: 3.4.7
使用框架: Vue 3

复现步骤

ModuleParseError: Module parse failed: Unexpected token (2:7)
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
| export { Http } from './http/http'

export type { HttpParams } from './types/http-params'
|

→ Watching... [2024/6/21 17:39:32]

node:internal/process/promises:289
triggerUncaughtException(err, true /* fromPromise */);
^

[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "[object Array]".] {
code: 'ERR_UNHANDLED_REJECTION'
}

期望结果

正常加载 并支持monorepo方式

实际结果

无法导出通用包功能

环境信息

👽 Taro v3.6.32


  Taro CLI 3.6.32 environment info:
    System:
      OS: Windows 11 10.0.22631
    Binaries:
      Node: 20.14.0 - D:\Program Files\nodejs\node.EXE
      Yarn: 1.22.19 - ~\AppData\Roaming\npm\yarn.CMD
      npm: 10.7.0 - D:\Program Files\nodejs\npm.CMD
    npmPackages:
      @tarojs/cli: 3.6.32 => 3.6.32 
      @tarojs/components: 3.6.32 => 3.6.32 
      @tarojs/helper: 3.6.32 => 3.6.32 
      @tarojs/plugin-framework-vue3: 3.6.32 => 3.6.32 
      @tarojs/plugin-platform-alipay: 3.6.32 => 3.6.32 
      @tarojs/plugin-platform-h5: 3.6.32 => 3.6.32 
      @tarojs/plugin-platform-jd: 3.6.32 => 3.6.32 
      @tarojs/plugin-platform-qq: 3.6.32 => 3.6.32 
      @tarojs/plugin-platform-swan: 3.6.32 => 3.6.32 
      @tarojs/plugin-platform-tt: 3.6.32 => 3.6.32 
      @tarojs/plugin-platform-weapp: 3.6.32 => 3.6.32 
      @tarojs/runtime: 3.6.32 => 3.6.32 
      @tarojs/shared: 3.6.32 => 3.6.32 
      @tarojs/taro: 3.6.32 => 3.6.32
      @tarojs/taro-loader: 3.6.32 => 3.6.32
      @tarojs/webpack5-runner: 3.6.32 => 3.6.32
      babel-preset-taro: 3.6.32 => 3.6.32
      eslint-config-taro: 3.6.32 => 3.6.32


补充信息

使用pnpm workspace方式

@DreamPWJ DreamPWJ changed the title Vue 初始化后报错 TypeError: (0 , vue__WEBPACK_IMPORTED_MODULE_0__.createElementVNode) is not a function pnpm workspace monorepo方式导出报错 You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file Jun 21, 2024
@TheKonka TheKonka added V-3 Version - 3.x F-vue3 Framework - Vue 3 labels Jun 21, 2024
This was referenced Jun 22, 2024
@koppthe
Copy link
Contributor

koppthe commented Jun 24, 2024

有最小可复现 demo 吗

@DreamPWJ
Copy link
Author

DreamPWJ commented Jun 24, 2024

好了,没有tsx编译, 现在集成nutUI 报错 vue__WEBPACK_IMPORTED_MODULE_1__.normalizeClass, 按照官方文档上配置不行

@DreamPWJ
Copy link
Author

image

@DreamPWJ
Copy link
Author

已搞定, 依赖版本和webpack配置有问题, 最新taro默认模板就有问题

@DreamPWJ
Copy link
Author

vue3 + nutui4模板没问题

@DreamPWJ
Copy link
Author

compiler: {
  type: 'webpack5',
  prebundle: { enable: false, force: true }  
}  需要设置

@Mudong-17
Copy link

设置了也没有效果,Taro React,微信小程序

compiler: {
  type: 'webpack5',
  prebundle: { enable: false, force: true }  
} 

@Yang03
Copy link
Contributor

Yang03 commented Jul 12, 2024

compile: {
     include: [(modulePath) => /node_modules|monoRepo/.test(modulePath)],
   }

引用的monoRepo 也要加到编译里

@zzhao8053
Copy link

修复了吗?

@DreamPWJ
Copy link
Author

不加 compile也能用, 修复了 , 并且开源了 https://github.com/DreamPWJ/mini-monorepo

@Yang03
Copy link
Contributor

Yang03 commented Jul 17, 2024

@DreamPWJ 讲下思路

@chioio
Copy link

chioio commented Jul 23, 2024

Error in React:

Module parse failed: Unexpected token (5:19)
packages/ui/src/Button/index.tsx
File was processed with these loaders:
 * ../../node_modules/.pnpm/@pmmmwh+react-refresh-webpack-plugin@0.5.15_react-refresh@0.11.0_type-fest@2.19.0_webpack-dev_p3avfqcvlze6pv6ak4bart7uku/node_modules/@pmmmwh/react-refresh-webpack-plugin/loader/index.js
 * ../../node_modules/.pnpm/unplugin@1.11.0/node_modules/unplugin/dist/webpack/loaders/transform.js
You may need an additional loader to handle the result of these loaders.
| import { Text } from '@tarojs/components'
| 
> export const Button: React.FC = () => {
|   return UI BUTTON
| }

@DreamPWJ 我看了你上面的例子,react的你用tsc编译了,我这边的情况是我 lib 里用到了 unocss,如果要用 tsc 或 tsup 的话就需要先编译 unocss 再 tsc/tsup

@chioio
Copy link

chioio commented Jul 27, 2024

Error in React:

Module parse failed: Unexpected token (5:19)
packages/ui/src/Button/index.tsx
File was processed with these loaders:
 * ../../node_modules/.pnpm/@pmmmwh+react-refresh-webpack-plugin@0.5.15_react-refresh@0.11.0_type-fest@2.19.0_webpack-dev_p3avfqcvlze6pv6ak4bart7uku/node_modules/@pmmmwh/react-refresh-webpack-plugin/loader/index.js
 * ../../node_modules/.pnpm/unplugin@1.11.0/node_modules/unplugin/dist/webpack/loaders/transform.js
You may need an additional loader to handle the result of these loaders.
| import { Text } from '@tarojs/components'
| 
> export const Button: React.FC = () => {
|   return UI BUTTON
| }

@DreamPWJ 我看了你上面的例子,react的你用tsc编译了,我这边的情况是我 lib 里用到了 unocss,如果要用 tsc 或 tsup 的话就需要先编译 unocss 再 tsc/tsup

我找到了个方法,在 config/index.ts 下配置 h5/mini 的 compile

  // ...
  compile: {
        include: [() => '@org/ui'],
  }
  // ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-vue3 Framework - Vue 3 V-3 Version - 3.x
Projects
None yet
Development

No branches or pull requests

7 participants