node.js - Parcel+Sass+npm:“错误:无法安装@parcel/transformer-sass:回调必须是函数。收到未定义
问题描述
我正在尝试使用 Parcel 构建一个库,并尝试将一个index.scss
文件导入我的index.js
文件中,如果我不将它作为依赖项包含它,它要么无法“安装 @parcel/transformer-sass”,要么“不能”当我安装它时找到模块“@parcel/transformer-sass”。index.css' file into
值得注意的是,如果我改为导入 index.js` ,Parcel 将成功构建。
有谁知道我做错了什么?
npm i @parcel/transformer-scss
作为依赖项安装,我得到错误:
× Build failed.
Error: Failed to install @parcel/transformer-sass: Callback must be a function. Received undefined
Error: Failed to install @parcel/transformer-sass: Callback must be a function. Received undefined
at install
(C:\...\nvm\v14.18.0\node_modules\parcel\node_modules\@parcel\package-manager\lib\installPackage.js:131:11)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async PromiseQueue._runFn
(C:\...\nvm\v14.18.0\node_modules\parcel\node_modules\@parcel\utils\lib\PromiseQueue.js:88:7)
at async PromiseQueue._next
(C:\...\nvm\v14.18.0\node_modules\parcel\node_modules\@parcel\utils\lib\PromiseQueue.js:75:5)
安装@parcel/transformer-sass
and @parcel/config-default
,我收到错误:
× Build failed.
@parcel/core: Cannot find Parcel plugin "@parcel/transformer-sass"
C:\...\nvm\v14.18.0\node_modules\parcel\node_modules\@parcel\config-default\index.json:25:23
24 | "*.{styl,stylus}": ["@parcel/transformer-stylus"],
> 25 | "*.{sass,scss}": ["@parcel/transformer-sass"],
> | ^^^^^^^^^^^^^^^^^^^^^^^^^^ Cannot find module "@parcel/transformer-sass"
26 | "*.less": ["@parcel/transformer-less"],
27 | "*.{css,pcss}": ["@parcel/transformer-postcss", "@parcel/transformer-css"],
我还尝试创建.parcelrc
各种配置,包括:
{
"transformers":{".scss":"@parcel/transformer-scss"}
}
和
{
"extends":"@parcel/config-default",
"transformers":{".scss":"@parcel/transformer-scss"}
}
这会引发类似的错误。
这是我的package.json
:
"name": "frontend",
"version": "1.0.0",
"description": "",
"source": "src/index.js",
"targets": {
"default": {
"distDir": "../staticfiles"
}
},
"main": "index.js",
"module": "module.js",
"scripts": {
"watch": "parcel watch",
"build": "parcel build"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"parcel": "latest"
},
"dependencies": {
"@parcel/config-default": "^2.0.0",
"@parcel/transformer-sass": "^2.0.0",
"@popperjs/core": "^2.10.2",
"bootstrap": "^5.1.3",
"bootstrap-table": "^1.18.3",
"jquery": "^3.6.0"
}
}
这是我的index.js
:
import "./index.scss";
import 'bootstrap';
import 'bootstrap-table';
import $ from "jquery";
console.log($)
window.jQuery = $;
window.$ = $;
console.log("hello world");
$(function() {
$('#table').bootstrapTable()
})
这是我的index.scss
:
@import "bootstrap/scss/bootstrap";
@import "bootstrap-table/dist/bootstrap-table";
// @import "bootstrap-table/dist/extenstions/filter-control/bootstrap-table-filter-control";
$body-color: slateblue;
body {
color: $body-color;
font-family: sans-serif;
}
解决方案
Callback must be a function. Received undefined
在具有(不相关)yarn.lock
文件的父目录的项目目录中使用 parcel 时会出现问题。
要重现运行touch ~/yarn.lock
,然后在~/
.
要解决此问题,请删除yarn.lock
父目录中的所有文件。
推荐阅读
- sql - 如何在另一列中选择需要特定内容的列
- .net - 如何序列化 (NewtonSoft) 包含具有名为 Type 的属性的接口的类?
- c - 在 linux 中编写一个健壮的计时器
- python - 在 tSNE 图上注释几个点 - 如果可能,每个集群几个点
- flutter - 如何将数据从子小部件传递到飞镖中的父小部件?
- twitter-bootstrap - Bootstrap 成功按钮的用例是什么?
- java - 循环计算百分比数次Java
- c++ - 为向量分配内存并更改大小而不调用默认构造函数
- algorithm - 如何计算生产中现有代码的时间复杂度
- minikube - 为什么 YugaByteDB YSQL 选择查询在使用 bytea 数据类型时会返回意外字节?