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

从1.2.26 升级到 1.3.8 跨平台文件引用报错 #3791

Closed
innocces opened this issue Jul 12, 2019 · 6 comments
Closed

从1.2.26 升级到 1.3.8 跨平台文件引用报错 #3791

innocces opened this issue Jul 12, 2019 · 6 comments

Comments

@innocces
Copy link
Contributor

问题描述
[问题描述:站在其它人的角度尽可能清晰地、简洁地把问题描述清楚]
升级Taro并更新项目依赖后,跨平台文件报错,报错./.temp/pages/courseMain/courseMain.js Module not found: Can't resolve '@utils/methods' in 'E:\aiyomi-h5\.temp\pages\courseMain'

复现步骤
[复现问题的步骤]

  1. 由于taro update self更新后本地taro版本未更新,所以从新安装了最新版的yarn global add @tarojs/cli@latest
  2. 执行taro update project更新项目依赖
  3. 执行yarn dev:h5之后跨平台文件编译报错,如下图
    778c3430459128e89263f1718c8e685
    6aaf29d7629c9bc4b7f4a6695631bc1
    611744a3eae27279362653dd89d3e1c

期望行为
期望编译无问题

报错信息
6aaf29d7629c9bc4b7f4a6695631bc1

系统信息

taro info
👽 Taro v1.3.8


  Taro CLI 1.3.8 environment info:
    System:
      OS: Windows 10
    Binaries:
      Node: 10.15.1 - F:\soft\nodejs\node.EXE
      Yarn: 1.16.0 - C:\Users\qq\AppData\Roaming\npm\yarn.CMD
      npm: 6.4.1 - F:\soft\nodejs\npm.CMD

补充信息
[可选]
[根据你的调查研究,出现这个问题的原因可能在哪里?]

@taro-bot
Copy link

taro-bot bot commented Jul 12, 2019

欢迎提交 Issue~

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

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

Good luck and happy coding~

@Littly
Copy link
Contributor

Littly commented Jul 12, 2019

看一下你的alias配置?

@innocces
Copy link
Contributor Author

alias: {
    '@actions': path.resolve(__dirname, '..', 'src/actions'),
    '@static': path.resolve(__dirname, '..', 'src/static'),
    '@image': path.resolve(__dirname, '..', 'src/static/image'),
    '@components': path.resolve(__dirname, '..', 'src/components'),
    '@constants': path.resolve(__dirname, '..', 'src/constants'),
    '@reducers': path.resolve(__dirname, '..', 'src/reducers'),
    '@styles': path.resolve(__dirname, '..', 'src/styles'),
    '@utils': path.resolve(__dirname, '..', 'src/utils'),
    '@const': path.resolve(__dirname, '..', 'src/const'),
    '@pages': path.resolve(__dirname, '..', 'src/pages')
  },

@innocces
Copy link
Contributor Author

整体配置和模版基本无差异,下面是完整配制

const path = require('path')
console.log(path.resolve(__dirname, '..', 'src/styles/theme.scss'))
// NOTE 在 sass 中通过别名(@ 或 ~)引用需要指定路径
const sassImporter = function(url) {
  if (url[0] === '~' && url[1] !== '/') {
    return {
      file: path.resolve(__dirname, '..', 'node_modules', url.substr(1))
    }
  }

  const reg = /^@styles\/(.*)/
  return {
    file: reg.test(url) ? path.resolve(__dirname, '..', 'src/styles', url.match(reg)[1]) : url
  }
}

const config = {
  projectName: 'aiyomi-h5',
  date: '2019-4-16',
  designWidth: 750,
  deviceRatio: {
    '640': 2.34 / 2,
    '750': 1,
    '828': 1.81 / 2
  },
  sourceRoot: 'src',
  outputRoot: 'dist',
  plugins: {
    babel: {
      sourceMap: true,
      presets: [
        ['env', {
          modules: false
        }]
      ],
      plugins: [
        'transform-decorators-legacy',
        'transform-class-properties',
        'transform-object-rest-spread'
      ]
    },
    sass: {
      importer: sassImporter,
      resource: path.resolve(__dirname, '..', 'src/styles/theme.scss'),
      projectDirectory: path.resolve(__dirname, '..')
    }
  },
  defineConstants: {
  },
  alias: {
    '@actions': path.resolve(__dirname, '..', 'src/actions'),
    '@static': path.resolve(__dirname, '..', 'src/static'),
    '@image': path.resolve(__dirname, '..', 'src/static/image'),
    '@components': path.resolve(__dirname, '..', 'src/components'),
    '@constants': path.resolve(__dirname, '..', 'src/constants'),
    '@reducers': path.resolve(__dirname, '..', 'src/reducers'),
    '@styles': path.resolve(__dirname, '..', 'src/styles'),
    '@utils': path.resolve(__dirname, '..', 'src/utils'),
    '@const': path.resolve(__dirname, '..', 'src/const'),
    '@pages': path.resolve(__dirname, '..', 'src/pages')
  },
  copy: {
    patterns: [
    ],
    options: {
    }
  },
  weapp: {
    module: {
      postcss: {
        autoprefixer: {
          enable: true,
          config: {
            browsers: [
              'last 3 versions',
              'Android >= 4.1',
              'ios >= 8'
            ]
          }
        },
        pxtransform: {
          enable: true,
          config: {

          }
        },
        url: {
          enable: true,
          config: {
            limit: 10240 // 设定转换尺寸上限
          }
        },
        cssModules: {
          enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
          config: {
            namingPattern: 'module', // 转换模式,取值为 global/module
            generateScopedName: '[name]__[local]___[hash:base64:5]'
          }
        }
      }
    }
  },
  h5: {
    // NOTE H5 打包静态资源时带 hash 值,方便缓存、版本管理
    publicPath: '/',
    staticDirectory: 'static',
    esnextModules: ['taro-ui'],
    output: {
      filename: 'js/[name].[hash].js',
      chunkFilename: 'js/[name].[chunkhash].js'
    },
    imageUrlLoaderOption: {
      limit: 5000,
      name: 'static/images/[name].[hash].[ext]'
    },
    miniCssExtractPluginOption: {
      filename: 'css/[name].[hash].css',
      chunkFilename: 'css/[name].[chunkhash].css',
    },
    module: {
      postcss: {
        autoprefixer: {
          enable: true,
          config: {
            browsers: [
              'last 3 versions',
              'Android >= 4.1',
              'ios >= 8'
            ]
          }
        },
        cssModules: {
          enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
          config: {
            namingPattern: 'module', // 转换模式,取值为 global/module
            generateScopedName: '[name]__[local]___[hash:base64:5]'
          }
        }
      }
    },
    sassLoaderOption: {
      importer: sassImporter
    },
    fontUrlLoaderOption: {
      test: /\.(eot|ttf|svg|woff)$/i,
      use: [
        {
          loader: 'url-loader',
          options: {
            limit: 8192,
          },
        }
      ]
    }
  }
}

module.exports = function (merge) {
  if (process.env.NODE_ENV === 'development') {
    return merge({}, config, require('./dev'))
  }
  return merge({}, config, require('./prod'))
}

@Littly
Copy link
Contributor

Littly commented Jul 12, 2019

ok 我看下

@innocces
Copy link
Contributor Author

ok 我看下

(:з」∠)

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