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

TypeError: defaultLoader is not a function #1493

Closed
matcool opened this issue Jan 12, 2021 · 11 comments
Closed

TypeError: defaultLoader is not a function #1493

matcool opened this issue Jan 12, 2021 · 11 comments

Comments

@matcool
Copy link

matcool commented Jan 12, 2021

Describe the bug

yarn build fails on the vue-ts template

Reproduction

Create a new project with the vue-ts template

yarn create @vitejs/app

Install dependencies

yarn

Build

yarn build

System Info

  • vite version: 2.0.0-beta.12
  • Operating System: Windows 10
  • Node version: v14.15.4
  • Package manager (npm/yarn/pnpm) and version: yarn 1.22.0

Logs (Optional if provided reproduction)

$ C:\projects\vite-test\node_modules\.bin\vite build --debug
failed to load config from /projects/vite-test/vite.config.ts
error during build:
TypeError: defaultLoader is not a function
    at Object.require.extensions.<computed> [as .ts] (C:\projects\vite-test\node_modules\vite\dist\node\chunks\dep-30d01443.js:46937:13)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at loadConfigFromBundledFile (C:\projects\vite-test\node_modules\vite\dist\node\chunks\dep-30d01443.js:46941:17)
    at loadConfigFromFile (C:\projects\vite-test\node_modules\vite\dist\node\chunks\dep-30d01443.js:46888:32)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async resolveConfig (C:\projects\vite-test\node_modules\vite\dist\node\chunks\dep-30d01443.js:46650:28)
    at async doBuild (C:\projects\vite-test\node_modules\vite\dist\node\chunks\dep-30d01443.js:39447:20)
error Command failed with exit code 1.
@ghost
Copy link

ghost commented Jan 12, 2021

This problem occurs in window10. Basically 100% recurring

@ghost
Copy link

ghost commented Jan 12, 2021

2.0.0-beta.12 This will automatically match up to 2.0.0-beta.22. I think it may be caused by this submission 803f6da

@ghost
Copy link

ghost commented Jan 12, 2021

@yyx990803 Can this problem be solved first? Otherwise, the current window users will not be able to use beta.22 after installing it. Only manually fix the version to beta.21

@ruizer
Copy link

ruizer commented Jan 12, 2021

yes,me too.
2.0.0-beta.12 is OK,2.0.0-beta.21 is aslo good,but 2.0.0-beta.22 will have this problem

@softminer
Copy link

yes,me too.Please solve it.

@giusepperaso
Copy link

Having this problem too, in 2.0.0-beta.12; I can only run the project by switching to a .js config file and by replacing es6 import / export with common js syntax

@antfu
Copy link
Member

antfu commented Jan 12, 2021

Can anyone help on debugging this and maybe even draft a PR for it? I'll look into this later. Thanks!

@yyx990803
Copy link
Member

Hmm, weird how the windows CI passed 🤔

@shashwatsingh
Copy link

I got the same error message on Windows 10 with vite 2.0, but with a slight change: my working directory is a symlink to a longer path.

I was not sure if this is a supported use-case, so please ignore if not.

Details:
Actual directory: C:\Users\<user>Documents\js\viteapp
Symlink: c:\work\viteapp (created using mklink /D c:\work C:\Users\<user>\Documents\js\)

Vite Version:

vite@^2.0.0:
  version "2.0.0"
  resolved "https://registry.yarnpkg.com/vite/-/vite-2.0.0.tgz#156f35eadaa7947629aa8a24eb23129b07116ee3"
  integrity sha512-rNli5g0DaQ6+btlRqkmaR06neWaJGApmt40gocqrYDNi2XoEXYQgKiHSWzMeUgc1Cdva2HduqazaE+RaKjBpdQ==
  dependencies:
    esbuild "^0.8.34"
    postcss "^8.2.1"
    resolve "^1.19.0"
    rollup "^2.38.5"
  optionalDependencies:
    fsevents "~2.3.1"

Steps (happens in Windows Command Prompt (cmd.exe) and Windows Terminal (wt.exe):

C:\work\viteapp>yarn dev
yarn run v1.22.5
warning package.json: No license field
$ vite
failed to load config from C:\work\viteapp\vite.config.ts
error when starting dev server:
TypeError: defaultLoader is not a function
    at Object.require.extensions.<computed> [as .ts] (C:\Users\SS\Documents\js\viteapp\node_modules\vite\dist\node\chunks\dep-9bcbff8e.js:48440:13)
    at Module.load (node:internal/modules/cjs/loader:973:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    at Module.require (node:internal/modules/cjs/loader:997:19)
    at require (node:internal/modules/cjs/helpers:92:18)
    at loadConfigFromBundledFile (C:\Users\SS\Documents\js\viteapp\node_modules\vite\dist\node\chunks\dep-9bcbff8e.js:48445:17)
    at loadConfigFromFile (C:\Users\SS\Documents\js\viteapp\node_modules\vite\dist\node\chunks\dep-9bcbff8e.js:48381:32)
    at processTicksAndRejections (node:internal/process/task_queues:94:5)
    at async resolveConfig (C:\Users\SS\Documents\js\viteapp\node_modules\vite\dist\node\chunks\dep-9bcbff8e.js:48007:28)
    at async createServer$2 (C:\Users\SS\Documents\js\viteapp\node_modules\vite\dist\node\chunks\dep-9bcbff8e.js:67828:20)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

It runs after I move into the actual directory:

C:\work\viteapp>cd C:\Users\SS\Documents\js\viteapp\

C:\Users\SS\Documents\js\viteapp>yarn dev
yarn run v1.22.5
warning package.json: No license field
$ vite
Pre-bundling dependencies:
  vue
(this will be run only when your dependencies or config have changed)

 ⚡ Vite dev server running at:

  > Network:  http://192.168.43.231:3000/
  > Local:    http://localhost:3000/
  > Network:  http://xxx.xx.xxx.xx:3000/

  ready in 2878ms.

@kwbtdisk
Copy link

I spent hours for this problem but resolved just rename vite.config.ts => vite.config.js
(I guess the config file will be loaded before typescript loader will load or something)

@ZYinMD
Copy link

ZYinMD commented Jul 3, 2021

I confirm it's because of symlink. I can now reliably reproduce it.

A very common thing that people do is putting their code in somewhere like ~/all-my-projects/foo/bar/vite-app, where all-my-projects is a symlink. If you run vite to start the dev server in such a location, you'll get the error.

To fix, cd into the real folder, make sure no parent folder is a symlink, then try again.

@github-actions github-actions bot locked and limited conversation to collaborators Jul 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

10 participants