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

taro1.2.0-beta.3 css modules 报错: Cannot read property 'exports' of undefined #1257

Closed
lbb00 opened this issue Nov 27, 2018 · 4 comments
Closed

Comments

@lbb00
Copy link

lbb00 commented Nov 27, 2018

问题描述
测试了一波新鲜出炉的css modules,发现控制台报错:

Cannot read property 'exports' of undefined.

复现步骤
使用taro1.2.0-beta.3 生成一个新项目,然后将pages/index中的import './index.scss/' 修改为 import styles from './index.scss/'

在index.scss中写入一个.base{ color: #000;},并在index中使用 的方式使用

报错信息

生成  替换代码  为文件 /data/work/myApp/src/pages/index/index.js 生成 css modules
错误  页面编译  页面/data/work/myApp/src/pages/index/index编译失败!
TypeError: Cannot read property 'exports' of undefined
    at ImportDeclaration (/usr/local/lib/node_modules/@tarojs/cli/src/weapp.js:432:36)
    at NodePath._call (/usr/local/lib/node_modules/@tarojs/cli/node_modules/[email protected]@babel-traverse/lib/path/context.js:76:18)
    at NodePath.call (/usr/local/lib/node_modules/@tarojs/cli/node_modules/[email protected]@babel-traverse/lib/path/context.js:48:17)
    at NodePath.visit (/usr/local/lib/node_modules/@tarojs/cli/node_modules/[email protected]@babel-traverse/lib/path/context.js:105:12)
    at TraversalContext.visitQueue (/usr/local/lib/node_modules/@tarojs/cli/node_modules/[email protected]@babel-traverse/lib/context.js:150:16)
    at TraversalContext.visitMultiple (/usr/local/lib/node_modules/@tarojs/cli/node_modules/[email protected]@babel-traverse/lib/context.js:103:17)
    at TraversalContext.visit (/usr/local/lib/node_modules/@tarojs/cli/node_modules/[email protected]@babel-traverse/lib/context.js:190:19)
    at Function.traverse.node (/usr/local/lib/node_modules/@tarojs/cli/node_modules/[email protected]@babel-traverse/lib/index.js:114:17)
    at NodePath.visit (/usr/local/lib/node_modules/@tarojs/cli/node_modules/[email protected]@babel-traverse/lib/path/context.js:115:19)
    at TraversalContext.visitQueue (/usr/local/lib/node_modules/@tarojs/cli/node_modules/[email protected]@babel-traverse/lib/context.js:150:16)

系统信息

  • mac os
  • v1.2.0-beta.3
  • Node.js 10
  • weapp
@taro-bot
Copy link

taro-bot bot commented Nov 27, 2018

欢迎提交 Issue~

如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏

如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。

Good luck and happy coding~

@luckyadam
Copy link
Member

luckyadam commented Nov 27, 2018

因为没有配置开启,默认是关的
config/index.js 里,weapp.module.postcss 下增加这个配置

cssModules: {
    enable: true,  // 默认为 false
    config: {
      generateScopedName: '[name]__[local]___[hash:base64:5]'
    }
  }

https://nervjs.github.io/taro/docs/css-modules.html

@lbb00
Copy link
Author

lbb00 commented Nov 27, 2018

@luckyadam 嗯,多谢了。我体验了一下,我觉得当前的规整不太友好。看了一下#933的讨论。我也觉得按照create-react-app 的方案来更好。 #933 (comment)

@lbb00
Copy link
Author

lbb00 commented Nov 27, 2018

@luckyadam 我新建了一个issues来讨论这个问题 #1266

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

No branches or pull requests

2 participants