以下是我的node.js文件的摘录 我正在尝试将代码从LESS编译成CSS。 我错过了什么
app.use(lessMiddleware({
src: path.join(__dirname, '/public/stylesheets/styles', 'less'),
dest: path.join(__dirname, '/public/stylesheets/css'),
prefix : '/stylesheets',
}));
当我刷新index.html时,它会将我抛出错误
TypeError: Arguments to path.join must be strings
at f (path.js:204:15)
at Object.filter (native)
at Object.exports.join (path.js:209:40)
at C:\SrkOwnRepo\Hotaaal\HotelUI10892515\node_modules\less-middleware\lib\mi
ddleware.js:161:27
at Layer.handle [as handle_request] (C:\SrkOwnRepo\Hotaaal\HotelUI10892515\n
ode_modules\express\lib\router\layer.js:95:5)
at trim_prefix (C:\SrkOwnRepo\Hotaaal\HotelUI10892515\node_modules\express\l
ib\router\index.js:312:13)
at C:\SrkOwnRepo\Hotaaal\HotelUI10892515\node_modules\express\lib\router\ind
ex.js:280:7
at Function.process_params (C:\SrkOwnRepo\Hotaaal\HotelUI10892515\node_modul
es\express\lib\router\index.js:330:12)
at next (C:\SrkOwnRepo\Hotaaal\HotelUI10892515\node_modules\express\lib\rout
er\index.js:271:10)
at expressInit (C:\SrkOwnRepo\Hotaaal\HotelUI10892515\node_modules\express\l
ib\middleware\init.js:33:5)
TypeError: Arguments to path.join must be strings
at f (path.js:204:15)
at Object.filter (native)
at Object.exports.join (path.js:209:40)
at C:\SrkOwnRepo\Hotaaal\HotelUI10892515\node_modules\less-middleware\lib\mi
ddleware.js:161:27
at Layer.handle [as handle_request] (C:\SrkOwnRepo\Hotaaal\HotelUI10892515\n
ode_modules\express\lib\router\layer.js:95:5)
at trim_prefix (C:\SrkOwnRepo\Hotaaal\HotelUI10892515\node_modules\express\l
ib\router\index.js:312:13)
at C:\SrkOwnRepo\Hotaaal\HotelUI10892515\node_modules\express\lib\router\ind
ex.js:280:7
at Function.process_params (C:\SrkOwnRepo\Hotaaal\HotelUI10892515\node_modul
es\express\lib\router\index.js:330:12)
at next (C:\SrkOwnRepo\Hotaaal\HotelUI10892515\node_modules\express\lib\rout
er\index.js:271:10)
at expressInit (C:\SrkOwnRepo\Hotaaal\HotelUI10892515\node_modules\express\l
ib\middleware\init.js:33:5)
请提供变通方法或任何其他中间件。
答案 0 :(得分:0)
less-middleware function的界面与您在代码段中显示的界面不同。
看起来像lessMiddleware(source, options)
,其中source
是字符串,options
是对象。当它试图在path.join
上调用source
时,它会在here附近出现中断,在您的情况下是一个对象。
您可以在documentation of the middleware中查看选项中已接受的参数。