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

h5 编译失败 #4042

Closed
MonchiLin opened this issue Aug 1, 2019 · 5 comments
Closed

h5 编译失败 #4042

MonchiLin opened this issue Aug 1, 2019 · 5 comments

Comments

@MonchiLin
Copy link

问题描述
编译小程序一切正常, 编译 h5 就会报错, 确认 src 下面无被 eslint 警告的代码

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

  1. npm run dev:h5

期望行为
正常编译

报错信息

终端提示的如下:

创建  发现文件  src\typings\amap\plugin\polygon.d.ts (上面还有很多创建文件 xx)

| Compiling...{ SyntaxError: Unexpected token (1:6)
    at Parser.pp$4.raise (项目地址打码\node_modules\acorn\dist\acorn.js:2757:13)
    at Parser.pp.unexpected (项目地址打码\node_modules\acorn\dist\acorn.js:647:8)
    at Parser.pp.expect (项目地址打码\node_modules\acorn\dist\acorn.js:641:26)
    at Parser.pp$3.parseParenAndDistinguishExpression (项目地址打码\node_modules\acorn\dist\acorn.js:2228:38)

    at Parser.pp$3.parseExprAtom (项目地址打码\node_modules\acorn\dist\acorn.js:2163:41)
    at Parser.parseExprAtom (项目地址打码\node_modules\acorn-dynamic-import\lib\inject.js:60:31)
    at Parser.pp$3.parseExprSubscripts (项目地址打码\node_modules\acorn\dist\acorn.js:2047:19)
    at Parser.pp$3.parseMaybeUnary (项目地址打码\node_modules\acorn\dist\acorn.js:2024:17)
    at Parser.pp$3.parseExprOps (项目地址打码\node_modules\acorn\dist\acorn.js:1966:19)
    at Parser.pp$3.parseMaybeConditional (项目地址打码\node_modules\acorn\dist\acorn.js:1949:19)
    at Parser.pp$3.parseMaybeAssign (项目地址打码\node_modules\acorn\dist\acorn.js:1925:19)
    at Parser.pp$3.parseExpression (项目地址打码\node_modules\acorn\dist\acorn.js:1896:19)
    at Parser.pp$1.parseStatement (项目地址打码\node_modules\acorn\dist\acorn.js:815:45)
    at Parser.parseStatement (项目地址打码\node_modules\acorn-dynamic-import\lib\inject.js:47:31)
    at Parser.pp$1.parseTopLevel (项目地址打码\node_modules\acorn\dist\acorn.js:706:23)
    at Parser.parse (项目地址打码\node_modules\acorn\dist\acorn.js:551:15) pos: 6, loc: Position { line: 1, c
olumn: 6 }, raisedAt: 7 }


ℹ️  Listening at http://127.0.0.1:10086/

监听文件修改中...

✅  Compiled successfully!

配置

const path = require("path")

// baseTaroConfig 是一些 env 配置, 经测试删除后仍然会编译错误
const baseTaroConfig = require("./base")


const resolve = (...pathSegments) => path.resolve(__dirname, ...pathSegments)

const sassImporter = function (url) {
    if (url[0] === '~' && url[1] !== '/') {
        return {
            file: resolve('..', 'node_modules', url.substr(1))
        }
    }

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

const config = {
    alias: {
        "@": resolve("..", "src"),
        "@package": resolve("..", "package.json"),
        "@project": resolve("..", "project.config.json"),
    },
    projectName: 'administration-management-client',
    date: '2019-7-18',
    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
        }
    },
    defineConstants: {},
    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: 102400000000 // 设定转换尺寸上限
                    }
                },
                cssModules: {
                    enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
                    config: {
                        namingPattern: 'module', // 转换模式,取值为 global/module
                        generateScopedName: '[name]__[local]___[hash:base64:5]'
                    }
                }
            }
        }
    },
    h5: {
        esnextModules: ["taro-ui"],
        publicPath: '/',
        staticDirectory: 'static',
        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]'
                    }
                }
            }
        }
    }
}

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

浏览器控制台报错
eal2GV.png

系统信息

Taro CLI 1.3.10 environment info:
System:
OS: Windows 10
Binaries:
Node: 8.16.0
npm: 6.4.1

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

@taro-bot
Copy link

taro-bot bot commented Aug 1, 2019

欢迎提交 Issue~

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

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

Good luck and happy coding~

@MonchiLin
Copy link
Author

已解决, 原因就是因为 return merge({}, baseTaroConfig, config, require('./dev'))

taro 用的 merge 是 lodash 的 fp 版本, 导致合并到最后配置文件是以我的 baseTaroConfig 来决定的

你们这不是误导人吗? 用 fp 的版本就把空对象 {} 放最后一个参数啊!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

@taro-bot
Copy link

taro-bot bot commented Aug 15, 2019

Hello~

您的问题楼上已经提供了解决方案,如果没有更多的问题这个 issue 将在 15 天后被自动关闭。

如果您在这 15 天中更新更多信息自动关闭的流程会自动取消,如有其他问题也可以发起新的 Issue。

Good luck and happy coding~

@taro-bot taro-bot bot removed the to be closed label Aug 30, 2019
@taro-bot taro-bot bot closed this as completed Aug 30, 2019
@daiyun169
Copy link

已解决, 原因就是因为 return merge({}, baseTaroConfig, config, require('./dev'))

taro 用的 merge 是 lodash 的 fp 版本, 导致合并到最后配置文件是以我的 baseTaroConfig 来决定的

你们这不是误导人吗? 用 fp 的版本就把空对象 {} 放最后一个参数啊!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

怎么解决的?

@MonchiLin
Copy link
Author

已解决, 原因就是因为 return merge({}, baseTaroConfig, config, require('./dev'))
taro 用的 merge 是 lodash 的 fp 版本, 导致合并到最后配置文件是以我的 baseTaroConfig 来决定的
你们这不是误导人吗? 用 fp 的版本就把空对象 {} 放最后一个参数啊!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

怎么解决的?

很简单啊,用 FP 风格的传入参数咯,具体可以看源码,taro 用一个项目后就没写过小程序了。

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

3 participants