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

sass importer api failed in latest version #1764

Closed
shinken008 opened this issue Jul 28, 2022 · 5 comments
Closed

sass importer api failed in latest version #1764

shinken008 opened this issue Jul 28, 2022 · 5 comments
Assignees

Comments

@shinken008
Copy link

shinken008 commented Jul 28, 2022

env

node@14.17.6
sass@1.50.0

case 1 in sass@1.49.11

sass render option when file exists then the importer function did execute, node-sass success. I need to delete the file option to be successful.

Awful, when I ran in sass@1.50.0 or the latest version, it did fail.

Above issues, node-sass can be executed.

// const sass = require('node-sass'); // success
const sass = require('sass');
const fs = require('fs')
const path = require('path')

const file = path.join(__dirname, './style/components/button.scss')
const data = fs.readFileSync(file, { encoding: 'utf-8' }).toString()

sass.render({
  // file, // run success in sass@1.49.11 when I delete. run fail in sass@1.50.0
  data,
  importer: (...args) => {
    const [url, prev] = args
    const prevFile = path.isAbsolute(prev) ? prev : file
    const _file = path.resolve(path.dirname(prevFile), url)

    console.log('_file >>>>>>>>>>', _file)    
    //  success flag log:_file >>>>>>>>>> /Users/xx/project/style-process-test/src/style/variables/default.scss
    //  success flag log:_file >>>>>>>>>> /Users/xx/project/style-process-test/src/style/mixins/index.scss
    
    return {
      file: _file,
      contents: fs.readFileSync(_file, { encoding: 'utf-8' }).toString() }
  }
}, function (error, result) {
  if (error) {
    console.error(error);
  }
  else {
    console.log(result.css.toString());
  }
});
// style/components/button.scss
@import '../variables/default.scss';
@import '../mixins/index.scss';
.button {
    // 
}

case 2 nest importer in sass >= 1.37.5 failed

// style/components/button.scss
@import '../variables/default.scss';
@import '../mixins/index.scss';
.button {
    // 
}

nest import:

// @import '../mixins/index.scss';
@import './libs/absolute-center.scss';
@import './libs/clearfix.scss';
@import './libs/tint.scss';

when executing the success then console some log

_file >>>>>>>>>> /Users/xx/project/style-process-test/src/style/variables/default.scss
_file >>>>>>>>>> /Users/xx/project/style-process-test/src/style/mixins/index.scss
_file >>>>>>>>>> /Users/xx/project/style-process-test/src/style/mixins/libs/absolute-center.scss
_file >>>>>>>>>> /Users/xx/project/style-process-test/src/style/mixins/libs/clearfix.scss
_file >>>>>>>>>> /Users/x/project/style-process-test/src/style/mixins/libs/tint.scss

But failed in sass >= 1.38.0:

_file >>>>>>>>>> /Users/xx/project/style-process-test/src/style/variables/default.scss
_file >>>>>>>>>> /Users/xx/project/style-process-test/src/style/mixins/index.scss

nest import did not work in the importer API function.

@shinken008 shinken008 changed the title sass importer api fail in lastest version sass importer api fail in latest version Jul 28, 2022
@shinken008 shinken008 changed the title sass importer api fail in latest version sass importer api failed in latest version Jul 28, 2022
@shinken008
Copy link
Author

Actually, sass >= v1.38.0, nest importer failed.

@shinken008
Copy link
Author

@nex3
Copy link
Contributor

nex3 commented Aug 2, 2022

It looks like your reproduction repository either doesn't exist or is marked as private.

@shinken008
Copy link
Author

It looks like your reproduction repository either doesn't exist or is marked as private.

Oh, Sorry, I made a mistake aha. My reproduction repository is marked as public now.

@nex3 nex3 self-assigned this Aug 8, 2022
@nex3
Copy link
Contributor

nex3 commented Aug 9, 2022

I'm not sure why this was working differently before, but the behavior in your reproduction case with the latest Sass version is correct. Relative loads from the filesystem always take precedence over importer loads in order to preserve users' ability to locally reason about how their local files will work even if they have extra importers installed. Node Sass didn't always respect this, but that was a bug.

@nex3 nex3 closed this as not planned Won't fix, can't repro, duplicate, stale Aug 9, 2022
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