我尝试使用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
和@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;
}
3条答案
按热度按时间qjp7pelc1#
在项目目录中使用parcel时会出现
Callback must be a function. Received undefined
问题,该项目目录的父目录中包含(不相关的)yarn.lock
文件。要重新生成,请运行
touch ~/yarn.lock
,然后在~/
的子目录中运行parcel。要解决此问题,请删除父目录中的所有
yarn.lock
文件。kgqe7b3p2#
我在运行包裹时遇到了问题,可能是由于node.js更新,我更新了包裹并在那里安装了
@parcel/transformer-sass
:https://www.npmjs.com/package/@parcel/transformer-sass .之后,包裹工作正常。g0czyy6m3#
我遇到了类似的bug,考虑一下:您应该尝试完全删除node_modules,然后运行npm i,这将重新安装node_modules,并将正确的路径设置为@parcel/transformer-sass。确认后,运行npm start。这应该会成功构建。