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

Cannot build module inside .vue file #3

Open
vlad0337187 opened this issue Mar 8, 2019 · 5 comments · May be fixed by #4
Open

Cannot build module inside .vue file #3

vlad0337187 opened this issue Mar 8, 2019 · 5 comments · May be fixed by #4

Comments

@vlad0337187
Copy link

Hello.
Earlier used CaffeineScript separately - all worked well. Recently started project with .vue files instead of .html, .js, .css, .caffeine.
(something like jsx, but with .vue extension)

screenshot from 2019-03-08 14-02-39
screenshot from 2019-03-08 14-02-55

error text:

 ERROR  Failed to compile with 1 errors                                                                                                                       2:03:34 PM

 error  in ./src/components/opened-scenes.vue?vue&type=script&lang=caf&

Module build failed (from ./node_modules/caffeine-mc/webpack-loader.js):
Error: ENOENT: no such file or directory, stat '/home/vlad/Programs/own_projects/herbalist-web/node_modules/cache-loader/dist/cjs.js??ref--0-0!/home/vlad/Programs/own_projects/herbalist-web/node_modules/vue-loader/lib/index.js??vue-loader-options!/home/vlad/Programs/own_projects/herbalist-web/src/components/opened-scenes.vue?vue&type=script&lang=caf&'
    at Object.statSync (fs.js:871:3)
    at Object.statSync (/home/vlad/Programs/own_projects/herbalist-web/node_modules/graceful-fs/polyfills.js:295:24)
    at module.exports.SourceRoots.findSourceRootSync (/home/vlad/Programs/own_projects/herbalist-web/node_modules/caffeine-mc/build/index.js:1017:15)
    at Function.module.exports.FileCompiler.compileFileSync (/home/vlad/Programs/own_projects/herbalist-web/node_modules/caffeine-mc/build/index.js:1559:58)
    at Object.module.exports (/home/vlad/Programs/own_projects/herbalist-web/node_modules/caffeine-mc/webpack-loader.js:33:38)

 @ ./src/components/opened-scenes.vue?vue&type=script&lang=caf& 1:0-232 1:248-251 1:253-482 1:253-482
 @ ./src/components/opened-scenes.vue
 @ ./node_modules/babel-loader/lib!./node_modules/coffee-loader!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/components/main-menu.vue?vue&type=script&lang=coffee&
 @ ./src/components/main-menu.vue?vue&type=script&lang=coffee&
 @ ./src/components/main-menu.vue
 @ ./node_modules/babel-loader/lib!./node_modules/coffee-loader!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/app.vue?vue&type=script&lang=coffee&
 @ ./src/app.vue?vue&type=script&lang=coffee&
 @ ./src/app.vue
 @ ./src/main.js
 @ multi (webpack)-dev-server/client?http://192.168.0.108:8080/sockjs-node (webpack)/hot/dev-server.js ./src/main.js

vue plugin for CaffeineScript:

https://github.com/vlad1777d/vue-cli-plugin-caffeine-todo

File index.js just adds Caffeine webpack loader to webpack config.
File generator.js just adds caffeine-script package to package.json
So almost nothing vue-specific here.

I think that problem is related to impossibility to parse inline text inside .vue file by caffeine webpack loader.
Maybe you could see anything here.
Will try to solve it manually that time.

@vlad0337187
Copy link
Author

vlad0337187 commented Mar 8, 2019

Error is because here:
https://github.com/caffeine-suite/caffeine-mc/blob/master/source/CaffeineMc/FileCompiler.coffee#L20

in sourceFile variable we have such value:
/home/vlad/Programs/own_projects/herbalist-web/node_modules/cache-loader/dist/cjs.js??ref--0-0!/home/vlad/Programs/own_projects/herbalist-web/node_modules/vue-loader/lib/index.js??vue-loader-options!/home/vlad/Programs/own_projects/herbalist-web/src/components/opened-scenes.vue?vue&type=script&lang=caf&

How it was processed in coffescript.
They just compile passed to webpack loader source code.
In caffeinescript loader, we throw away that passed code, find source root, read source file (again) by it's path, and than reassign source variable with read code.

I suggest add here nested try-catch block:
https://github.com/caffeine-suite/caffeine-mc/blob/master/webpack-loader.coffee#L42

And if "standard" way of compiling failed, try to compile given by webpack source code with inline (if I understand this term rightly) source map (i.e. just compile caffeinescript source string to JS one).

So we wouldn't have any specific to Vue code, this should help to solve any further problems with integrating to other frameworks.

Or, maybe, to add check before try block: does file exists in file system.
If doesn't - compile it as string-to-string (caffeine-to-js).
If it exists - compile it with current way.

@shanebdavis
Copy link
Member

Interesting. I'm not familiar with how Vue handles compile-routing. I'm guessing this file doesn't actually exist in the file-system, at least not -exactly- as this string specifies:

/home/vlad/Programs/own_projects/herbalist-web/node_modules/cache-loader/dist/cjs.js??ref--0-0!/home/vlad/Programs/own_projects/herbalist-web/node_modules/vue-loader/lib/index.js??vue-loader-options!/home/vlad/Programs/own_projects/herbalist-web/src/components/opened-scenes.vue?vue&type=script&lang=caf&

CaffeineMC expects sourceFile to resolve to a real file. Could you post the "real" file's full path? Is it this?

/home/vlad/Programs/own_projects/herbalist-web/src/components/opened-scenes.vue

CaffeineMC should work if sourceFile is null. It 'should' work, but it may not. If it doesn't, that's a bug I can resolve.

Otherwise, sourceFile needs to be a real file...

@vlad0337187
Copy link
Author

@shanebdavis , yes, my file is /home/vlad/Programs/own_projects/herbalist-web/src/components/opened-scenes.vue

But that .vue file, as you see, doesn't have supported by caffeinescript structure.
Even if that weird link
(/home/vlad/Programs/own_projects/herbalist-web/node_modules/cache-loader/dist/cjs.js??ref--0-0!/home/vlad/Programs/own_projects/herbalist-web/node_modules/vue-loader/lib/index.js??vue-loader-options!/home/vlad/Programs/own_projects/herbalist-web/src/components/opened-scenes.vue?vue&type=script&lang=caf&)
could be passed, than there would be needed some hacks to parse it's caffeineScript sources.
Also .vue files can have several <script> tags with different blocks of script.

I think, it would be easier in case of such strange links, which are absent on file system, just to compile passed code.
This also could help avoiding problems with further integration of CaffeineScript to other frameworks.
As we see, sourceFile here is not null... And, probably, shouldn't.

What do you think about, at least, checking: is link in a valid format (for UNIX / WINDOWS), and if format is unknonwn - throw away it and think that sourceFile is absent ?

@vlad0337187
Copy link
Author

@shanebdavis , if you'd like to reproduce it, you can clone repository:
hg clone https://bitbucket.org/new_novel/herbalist-ui/src
update to commit where the issue is present:
hg update 8
install npm packages:
npm install
launch project to see error:
npm run serve

@vlad0337187
Copy link
Author

@shanebdavis , seems, I got it, file needs to be present there for automatic imports feature.

Can automatic imports be disabled for "real-time" compiling projects, like vue, or, probably, to compile it in browser ?

@vlad0337187 vlad0337187 linked a pull request Aug 24, 2019 that will close this issue
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

Successfully merging a pull request may close this issue.

2 participants