为什么不能导入来自sassDir的已发现眼镜模块的文件?

时间:2017-03-02 19:22:02

标签: sass gulp-sass node-sass eyeglass

我正在尝试开始使用eyeglass@1.2.1并遇到问题,虽然发现了 eyeglass 模块,但@import却失败了。

这是 gulp 任务(此时仅用 gulp 包装,因为我不知道如何获得漂亮的 eyeglass 调试输出否则)使用 node-sass 编译单个文件。

gulp.task('sass', () => {
  const options = eyeglass({
    file: path.join('test', 'test.scss'),
    engines: {
      sass: nodeSass
    }
  });
  return nodeSass.render(options, (err, result) => console.log(err, result));
});

发生这种情况:

eyeglass:modules discovered modules
eyeglass:modules    :root(test)
eyeglass:modules    ├── eyeglass@1.2.1
eyeglass:modules    ├── eyeglass-sample@0.0.3
eyeglass:modules    └── true@2.2.1
eyeglass:modules     +0ms
eyeglass:functions functions discovered in module eyeglass:
• eyeglass-asset-uri($registered-assets, $relative-path)
• eyeglass-normalize-uri($uri, $type: web)
• eyeglass-uri-preserve($uri)
• eyeglass-uri-restore($uri)
• eyeglass-version($module: eyeglass)
• eyeglass-fs-absolute-path($fs-registered-pathnames, $path-id, $segments...)
• eyeglass-fs-join($segments...)
• eyeglass-fs-exists($absolute-path)
• eyeglass-fs-path-separator()
• eyeglass-fs-list-files($directory, $glob: '*')
• eyeglass-fs-list-directories($directory, $glob: '*')
• eyeglass-fs-parse-filename($filename)
• eyeglass-fs-info($filename)
• eyeglass-fs-read-file($filename) +13ms
eyeglass:functions functions discovered in module eyeglass-sample:
• hello($name) +1ms
eyeglass:functions all discovered functions:
• eyeglass-asset-uri($registered-assets, $relative-path)
• eyeglass-normalize-uri($uri, $type: web)
• eyeglass-uri-preserve($uri)
• eyeglass-uri-restore($uri)
• eyeglass-version($module: eyeglass)
• eyeglass-fs-absolute-path($fs-registered-pathnames, $path-id, $segments...)
• eyeglass-fs-join($segments...)
• eyeglass-fs-exists($absolute-path)
• eyeglass-fs-path-separator()
• eyeglass-fs-list-files($directory, $glob: '*')
• eyeglass-fs-list-directories($directory, $glob: '*')
• eyeglass-fs-parse-filename($filename)
• eyeglass-fs-info($filename)
• eyeglass-fs-read-file($filename)
• hello($name)
[19:25:56] Finished 'sass' after 97 ms
eyeglass:import true can be imported from ~/eyeglass-test/test/test.scss +5ms
{ [Error: Error: Could not import true from any of the following locations:
  ~/eyeglass-test/test/true.scss
  ~/eyeglass-test/test/true.sass
  ~/eyeglass-test/test/true.css
  ~/eyeglass-test/test/_true.scss
  ~/eyeglass-test/test/_true.sass
  ~/eyeglass-test/test/_true.css
  ~/eyeglass-test/test/true/index.scss
  ~/eyeglass-test/test/true/index.sass
  ~/eyeglass-test/test/true/index.css
  ~/eyeglass-test/test/true/_index.scss
  ~/eyeglass-test/test/true/_index.sass
  ~/eyeglass-test/test/true/_index.css]
  status: 1,
  file: '~/eyeglass-test/test/test.scss',
  line: 1,
  column: 9,
  message: 'Error: Could not import true from any of the following locations:
    ~/eyeglass-test/test/true.scss
    ~/eyeglass-test/test/true.sass
    ~/eyeglass-test/test/true.css
    ~/eyeglass-test/test/_true.scss
    ~/eyeglass-test/test/_true.sass
    ~/eyeglass-test/test/_true.css
    ~/eyeglass-test/test/true/index.scss
    ~/eyeglass-test/test/true/index.sass
    ~/eyeglass-test/test/true/index.css
    ~/eyeglass-test/test/true/_index.scss
    ~/eyeglass-test/test/true/_index.sass
    ~/eyeglass-test/test/true/_index.css',
      formatted: 'Error: Error: Could not import true from any of the following locations:
    ~/eyeglass-test/test/true.scss
    ~/eyeglass-test/test/true.sass
    ~/eyeglass-test/test/true.css
    ~/eyeglass-test/test/_true.scss
    ~/eyeglass-test/test/_true.sass
    ~/eyeglass-test/test/_true.css
    ~/eyeglass-test/test/true/index.scss
    ~/eyeglass-test/test/true/index.sass
    ~/eyeglass-test/test/true/index.css
    ~/eyeglass-test/test/true/_index.scss
    ~/eyeglass-test/test/true/_index.sass
    ~/eyeglass-test/test/true/_index.css
  on line 1 of test/test.scss
  >> @import "true";
     --------^
  ' } null

我已尝试过几种潜在的 eyeglass 依赖关系,例如

  • 眼镜样品
  • 眼镜数学
  • 超对称

我遇到所有这些类型的失败,它们似乎在调试输出中可用,但尝试@import名称或@import sass eyeglass:import susy can be imported from ~/eyeglass-test/sass/_test.scss +14ms ... Error: File to import not found or unreadable: susy. 中的任何内容目录失败。

即使非常特定的消息表明 可导入的内容显示出来,我也会收到这些错误:

> DEBUG=* gulp sass
[12:51:50] Requiring external module babel-register
[12:51:53] Using gulpfile ~/Projects/eyeglass-test/gulpfile.babel.js
[12:51:53] Starting 'sass'...
  eyeglass:modules discovered modules
  eyeglass:modules  :root(eyeglass-test)
  eyeglass:modules  ├── eyeglass@1.2.1
  eyeglass:modules  └── susy@2.2.12
  eyeglass:modules   +0ms
[12:51:53] 'sass' errored after 29 ms
[12:51:53] TypeError: this.main is not a function
    at EyeglassModule.init (~/eyeglass-test/node_modules/eyeglass/lib/modules/EyeglassModule.js:80:33)
    at ~/eyeglass-test/node_modules/eyeglass/lib/modules/EyeglassModules.js:83:9
    at Array.forEach (native)
    at EyeglassModules.init (~/eyeglass-test/node_modules/eyeglass/lib/modules/EyeglassModules.js:82:13)
    at new Eyeglass (~/eyeglass-test/node_modules/eyeglass/lib/index.js:35:16)
    at Eyeglass (~/eyeglass-test/node_modules/eyeglass/lib/index.js:18:13)
    at Gulp.<anonymous> (~/eyeglass-test/gulpfile.babel.js:7:19)
    at module.exports (~/eyeglass-test/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:34:7)
    at Gulp.Orchestrator._runTask (~/eyeglass-test/node_modules/gulp/node_modules/orchestrator/index.js:273:3)
    at Gulp.Orchestrator._runStep (~/eyeglass-test/node_modules/gulp/node_modules/orchestrator/index.js:214:10)

如果我再次从头开始,我会碰到这个,我已经过去了(虽然我不记得怎么样):

new Eyeglass

以上是用于说明目的的最简化的案例。我尝试使用 eyeglass 文档中的替代方法以及eyeglass.Eyeglasseyeglass.sassOptions()以及enableImportOnce: false等问题。我有没有engines尝试过。我尝试通过 eyeglass 选项手动添加模块。我有没有importer尝试过。我已经尝试过,但没有提供 eyeglass 文档和问题中提到的默认includePaths。我已经尝试使用 node-sass gulp-sass sass-true 的runner方法(通过它 true 但是没有其他内容可以导入,因为 true 将自己添加到includePaths)。

我唯一没有尝试的东西 - 尽管我非常肯定它会起作用 - 是手动创建我自己的includePaths配置以包含的sass目录eyeglass 模块,因为不必这样做是我对使用 eyeglass 感兴趣的两个原因之一。我得到的印象是 通常 ,不应该设置readline()来使用 eyeglass 模块,但是,假设它是由我正在做的事情引起的,我不清楚我在所有这些不同尝试中创造的不可避免的常见情况一直要求我这样做。

交叉发布到https://github.com/sass-eyeglass/eyeglass/issues/164

1 个答案:

答案 0 :(得分:0)

我能够重复这几次,但不得不把它放下一点。当我回到它并为我尝试的各种事情设置个别例子时,我发现我已经比我想的更进一步,我的主要问题是:

  1. 真是独一无二的。还有一些关于如何最好地使用真实和眼镜的部分,我很蠢,但主要观点是存在的。
  2. Eyeglass不支持传递依赖如果它们是devDependencies ;模块作者需要确保在dependencies
  3. 中列出任何眼镜依赖项

    以下是我最终为故障排除创建的所有示例,以防它们对其他人有用。

    https://github.com/morewry/sass-eyeglass-examples