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: Illegal invocation #1190

Closed
faxinwang opened this issue Jan 9, 2021 · 2 comments
Closed

TypeError: Illegal invocation #1190

faxinwang opened this issue Jan 9, 2021 · 2 comments

Comments

@faxinwang
Copy link

faxinwang commented Jan 9, 2021

I'm using sass to compile sass/scss code in the runtime in electron application. When the page is loading, the follow error occurred:

TypeError: Illegal invocation
    at Object.eval (sass.dart.js?eaa0:57)
    at eval (sass.dart.js:90708)
    at Object../node_modules/sass/sass.dart.js (vendor.js:23281)
    at __webpack_require__ (app.js:854)
    at fn (app.js:151)
    at eval (web.vue?94bf:131)
    at Module../node_modules/ts-loader/index.js?!./node_modules/vue-loader/lib/index.js?!./src/components/compileSass.vue?vue&type=script&lang=ts& (0.js:296)
    at __webpack_require__ (app.js:854)
    at fn (app.js:151)
    at eval (compileSass.vue?625c:1)

This is my code:

// import sass from 'sass/sass.dart';
import sass from 'sass';

//version 1
function renderScss(code:string, type:'sass'|'scss' = 'scss')
{
    try{
       //if I common this two line, the error disappers
        const res = sass.renderSync( {data:code, indentedSyntax:type ==='sass'});
        return (res.css.toString());
    }catch(e){
        return e; //show err info
    }
}

//version 2, use promise
function renderScss2(code:string, type:'sass'|'scss' = 'scss')
{
    return new Promise( (resolve,reject) => {
        try{
           //if I common this two line, the error disappers
            const res = sass.renderSync( {data:code, indentedSyntax:type ==='sass'});
            resolve(res.css.toString());

            // tried this , got the same error
            // sass.render( 
            //     {data:code, indentedSyntax:type ==='sass'}, 
            //     (err, res) => err ? reject(err) : resolve(res.css.toString())
            // );
        }catch(e){
            reject(e)
        }
    })
}

I don't know where is the problem.

@jathak
Copy link
Member

jathak commented Jan 15, 2021

How is renderScss actually being called? I can't replicate the error just by calling it from within Node.

You mention Electron. Is Sass running within the Node part of the app or within the browser part? Sass depends on the filesystem, so it can't actually run in a browser (see #25).

@faxinwang
Copy link
Author

I move the code to main process and it works now. Thank you very much. 😄 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants