Skip to content

Cannot read properties of undefined (reading 'url') #120

Closed
@frederikbosch

Description

{
  "dependencies": {
    "normalize.css": "^8.0.1"
  },
  "devDependencies": {
    "sass-embedded": "^1.49.9"
  }
}
// index.js
require('sass-embedded').renderSync({
  file: 'screen.scss',
  includePaths: [__dirname + '/node_modules'],
  importer: (x) => {
    console.log('never arrives here');
    return x;
  }
});
// test.scss
p {
  margin-bottom: 1.5em;
}
// screen.scss
@import 'test.scss';
@import 'normalize.css/normalize';

The above setup results in:

/srv/libraries/dart-sass-test/node_modules/sass-embedded/dist/lib/src/legacy/index.js:41
        throw newLegacyException(error);
        ^

Error: Error: TypeError: Cannot read properties of undefined (reading 'url')
  ╷
3 │ @import 'normalize.css/normalize';
  │         ^^^^^^^^^^^^^^^^^^^^^^^^^
  ╵
  screen.scss 3:9  root stylesheet
    at handleCompileResponse (/srv/libraries/dart-sass-test/node_modules/sass-embedded/dist/lib/src/compile.js:213:15)
    at compileRequestSync (/srv/libraries/dart-sass-test/node_modules/sass-embedded/dist/lib/src/compile.js:148:24)
    at compileString (/srv/libraries/dart-sass-test/node_modules/sass-embedded/dist/lib/src/compile.js:26:12)
    at Object.renderSync (/srv/libraries/dart-sass-test/node_modules/sass-embedded/dist/lib/src/legacy/index.js:36:43)
    at Object.<anonymous> (/srv/libraries/dart-sass-test/index.js:2:26)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12) {
  status: 1,
  formatted: "Error: TypeError: Cannot read properties of undefined (reading 'url')\n" +
    '\x1B[34m  ╷\x1B[0m\n' +
    "\x1B[34m3 │\x1B[0m @import \x1B[31m'normalize.css/normalize'\x1B[0m;\n" +
    '\x1B[34m  │\x1B[0m \x1B[31m        ^^^^^^^^^^^^^^^^^^^^^^^^^\x1B[0m\n' +
    '\x1B[34m  ╵\x1B[0m\n' +
    '  screen.scss 3:9  root stylesheet',
  toString: [Function: toString],
  line: 3,
  column: 9,
  file: '/srv/libraries/dart-sass-test/screen.scss'
}

The order of the lines in screen.scss matter. The following succeeds:

// screen.scss
@import 'normalize.css/normalize';
@import 'test.scss';

And if you leave out the importer in the options passed to renderSync, it also succeeds. The error is not generated by the importer itself: it never reaches the console.log statement inside the importer.

I believe the error is related to expectingRelativeLoad property inside the LegacyImporterWrapper class. However, I was not able to solve the issue, otherwise I would have created a PR.

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions