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

Error when i use mongo with the build #40

Closed
4ov opened this issue Sep 23, 2020 · 11 comments · Fixed by #43 or #44
Closed

Error when i use mongo with the build #40

4ov opened this issue Sep 23, 2020 · 11 comments · Fixed by #43 or #44

Comments

@4ov
Copy link

4ov commented Sep 23, 2020

I'm trying to deploy simple api (deno - opine - mongo),
I get

error: Uncaught ReferenceError: default is not defined
const handler = mod.default;
                    ^
    at dev-server.ts:12:21

when i use mongo module from https://deno.land/x/[email protected]

@TooTallNate
Copy link
Collaborator

Can you show me your complete code for the API endpoint?

@4ov
Copy link
Author

4ov commented Sep 23, 2020

//app.ts
import { opine } from "https://deno.land/x/[email protected]/mod.ts";
import { MongoClient } from "https://deno.land/x/[email protected]/mod.ts";

const client = new MongoClient();
client.connectWithUri("URL");
const db = client.database("NAME");
const users = db.collection<any>("COLLECTION");

const app = opine();

app.use(async (req, res) => {
  res.json(
      await users.find({ name: { $ne: null } })
    )
});



app.listen();
export default app
vercel.json
{
    "builds" : [
        {"src" : "*.ts", "use" : "[email protected]"}
    ],
    "build": {
        "env": {
            "DENO_UNSTABLE" : "true"
        }
    }
}
#bash
>vc dev
error: Uncaught ReferenceError: default is not defined
const handler = mod.default;
                    ^
    at dev-server.ts:12:21

@TooTallNate
Copy link
Collaborator

Thanks for that. I've distilled the issue down to a bug in deno. See denoland/deno#7649.

@TooTallNate
Copy link
Collaborator

This was fixed in Deno v1.4.5, which is the default version in [email protected]. Please update to this new version and let me know if you have any further issues!

@4ov
Copy link
Author

4ov commented Oct 9, 2020

There's an error says error: Uncaught PermissionDenied: access to open a plugin: /home/ma/apps/mopd/.deno_plugins/deno_mongo_f39a1ed8e4b1f4eb61e96bf8794f19af.so, run again with the --allow-plugin flag
is there any way to configure deno's flags?

@TooTallNate
Copy link
Collaborator

Can you try [email protected]?

@4ov
Copy link
Author

4ov commented Oct 9, 2020

Finally, It's working now (on dev server).
This the error i get when i try to deploy it

Screenshot from 2020-10-10 01-04-57

@TooTallNate
Copy link
Collaborator

Are you setting the DEBUG env var? Try unsetting that.

@4ov
Copy link
Author

4ov commented Oct 10, 2020

I got this too
another error

@TooTallNate
Copy link
Collaborator

Looks like the mongo dependency is trying to write to the filesystem. In the serverless function environment, the filesystem is read-only, except for the /tmp directory. If possible, try to configure the module to write the necessary files to /tmp instead.

@TooTallNate
Copy link
Collaborator

Btw the issue with using DEBUG has been resolved.

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