Api - Cannot find module
See original GitHub issueHi, when i trying to go my api url i get this error, but others pages loads correct.
On my local machine it works. How can i fix that error?
nuxt.config.js
export default {
// Global page headers: https://go.nuxtjs.dev/config-head
head: {
title: "invest",
htmlAttrs: {
lang: "en"
},
meta: [
{ charset: "utf-8" },
{ name: "viewport", content: "width=device-width, initial-scale=1" },
{ hid: "description", name: "description", content: "" }
],
link: [{ rel: "icon", type: "image/x-icon", href: "/favicon.ico" }]
},
// Global CSS: https://go.nuxtjs.dev/config-css
css: [],
// Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
plugins: [
{
src: "~/plugins/storeUtils/getUserUid.js",
mode: "client"
},
{
src: "~/plugins/storeUtils/getCurrentPortfolioUid.js",
mode: "client"
}
],
// Auto import components: https://go.nuxtjs.dev/config-components
components: true,
// Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
buildModules: [["@nuxtjs/vuetify", { theme: { dark: true } }]],
router: {
middleware: ["auth"]
},
// Modules: https://go.nuxtjs.dev/config-modules
modules: [
[
"@nuxtjs/firebase",
{
config: {
apiKey: process.env.FIREBASE_API_KEY,
authDomain: "",
databaseURL: "",
projectId: "",
storageBucket: "",
messagingSenderId: "",
appId: ""
},
services: {
auth: {
persistence: "local",
initialize: {
onAuthStateChangedAction: "auth/onAuthStateChangedAction",
onIdTokenChangedAction: "auth/onIdTokenChangedAction",
subscribeManually: false
},
ssr: false
},
database: true
}
}
],
[
"vue-toastification/nuxt",
{
timeout: 5000
}
]
],
// Build Configuration: https://go.nuxtjs.dev/config-build
build: {},
serverMiddleware: [
{
path: "/api",
handler: "~/api/index.js"
}
]
};
package.json
{
"name": "invest",
"version": "1.0.0",
"private": true,
"scripts": {
"dev": "nuxt",
"build": "nuxt build",
"start": "nuxt start",
"generate": "nuxt generate"
},
"dependencies": {},
"devDependencies": {
"@nuxtjs/firebase": "^7.4.1",
"@tinkoff/invest-openapi-js-sdk": "^1.2.17",
"cheerio": "^1.0.0-rc.5",
"cookieparser": "^0.1.0",
"core-js": "^3.8.2",
"firebase": "^8.2.3",
"js-cookie": "^2.2.1",
"jwt-decode": "^3.1.2",
"nuxt": "^2.14.12",
"puppeteer": "^8.0.0",
"vue-toastification": "^1.7.11",
"@nuxtjs/vuetify": "^1.11.3"
}
}
vercel.json
{
"version": 2,
"builds": [
{
"src": "nuxt.config.js",
"use": "@nuxtjs/vercel-builder",
"config": {
"serverFiles": ["api/**"]
}
}
]
}
Build Logs
<html> <body>20:19:42.534 | Cloning github.com/Ultraviolence322/invest (Branch: master, Commit: 0b30f37) |
---|---|
20:19:43.396 | Cloning completed: 862.122ms |
20:19:43.431 | Analyzing source code… |
20:19:43.433 | Warning: Due to builds existing in your configuration file, the Build and Development Settings defined in your Project Settings will not apply. Learn More: https://vercel.link/unused-build-settings |
20:19:44.655 | Installing build runtime… |
20:19:47.552 | Build runtime installed: 2.897s |
20:19:50.337 | Looking up build cache… |
20:19:50.390 | Build cache not found |
20:19:51.672 | [log] Running with @nuxt/vercel-builder version 0.21.2 |
20:19:51.672 | [log] ----------------- Prepare build ----------------- |
20:19:51.672 | [log] Downloading files… |
20:19:51.672 | [log] Working directory: /vercel/path0 |
20:19:51.675 | [log] Using npm |
20:19:51.675 | [info] Prepare build took: 3.610547 ms |
20:19:51.676 | [log] ----------------- Install devDependencies ----------------- |
20:20:11.015 | > puppeteer@8.0.0 install /vercel/path0/node_modules/puppeteer |
20:20:11.015 | > node install.js |
20:20:12.075 | (node:467) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead. |
20:20:12.075 | (Use node --trace-deprecation ... to show where the warning was created) |
20:20:15.326 | Chromium (856583) downloaded to /vercel/path0/node_modules_dev/puppeteer/.local-chromium/linux-856583 |
20:20:15.388 | > core-js@3.6.5 postinstall /vercel/path0/node_modules/@firebase/polyfill/node_modules/core-js |
20:20:15.388 | > node -e “try{require(‘./postinstall’)}catch(e){}” |
20:20:15.455 | > core-js@2.6.12 postinstall /vercel/path0/node_modules/@nuxt/babel-preset-app/node_modules/core-js |
20:20:15.455 | > node -e “try{require(‘./postinstall’)}catch(e){}” |
20:20:15.623 | > protobufjs@6.11.2 postinstall /vercel/path0/node_modules/protobufjs |
20:20:15.623 | > node scripts/postinstall |
20:20:15.788 | > core-js@3.12.0 postinstall /vercel/path0/node_modules/core-js |
20:20:15.788 | > node -e “try{require(‘./postinstall’)}catch(e){}” |
20:20:15.853 | > nuxt@2.15.4 postinstall /vercel/path0/node_modules/nuxt |
20:20:15.853 | > opencollective || exit 0 |
20:20:16.815 | npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/watchpack-chokidar2/node_modules/fsevents): |
20:20:16.815 | npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {“os”:“darwin”,“arch”:“any”} (current: {“os”:“linux”,“arch”:“x64”}) |
20:20:16.824 | npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.3.2 (node_modules/fsevents): |
20:20:16.824 | npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {“os”:“darwin”,“arch”:“any”} (current: {“os”:“linux”,“arch”:“x64”}) |
20:20:16.828 | added 1452 packages from 668 contributors in 24.704s |
20:20:17.532 | 99 packages are looking for funding |
20:20:17.532 | run npm fund for details |
20:20:17.554 | [info] Install devDependencies took: 25878.59532 ms |
20:20:17.555 | [log] ----------------- Nuxt build ----------------- |
20:20:17.777 | [log] Running nuxt build --standalone --no-lock --config-file “nuxt.config.js” /vercel/path0 |
20:20:59.569 | [info] Nuxt build took: 42013.896767 ms |
20:20:59.569 | [log] ----------------- Install dependencies ----------------- |
20:21:04.962 | added 121 packages from 228 contributors in 4.95s |
20:21:04.996 | 5 packages are looking for funding |
20:21:04.996 | run npm fund for details |
20:21:05.013 | [info] Install dependencies took: 5444.190412 ms |
20:21:05.013 | [log] ----------------- Collect artifacts ----------------- |
20:21:07.092 | [info] Collect artifacts took: 2078.905379 ms |
20:21:07.437 | Uploading build outputs… |
20:21:08.669 | Deploying build outputs… |
20:21:13.683 | Build completed. Populating build cache… |
20:21:13.684 | [log] ----------------- Collect cache ----------------- |
20:21:17.540 | [info] 100 files collected from .nuxt |
20:21:21.390 | [info] 0 files collected from .vercel_cache |
20:21:27.134 | [info] 39529 files collected from node_modules_dev |
20:21:31.058 | [info] 2261 files collected from node_modules_prod |
20:21:31.060 | [info] Collect cache took: 17375.371977 ms |
20:21:50.872 | Uploading build cache [155.02 MB]… |
20:21:53.485 | Build cache uploaded: 2.635s |
20:21:54.010 | Done with “nuxt.config.js” |
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
9 - Stack Overflow
Error : Cannot find module './api' (Hyperledger composer) · Ask Question. Asked 4 years, 8 months ago. Modified 4 years, 6 months ago....
Read more >cannot find module [Node npm Error Solved] - freeCodeCamp
How to Fix the "cannot find module" Error · delete the node modules folder by running rm -rf node_modules · delete package.lock.json file...
Read more >How to resolve can't find module error in Node.js - Reactgo
To fix Cannot find module errors, install the modules properly by running a npm install command in the appropriate directory as your project's ......
Read more >Cannot find module 'api.js' #18 - sveltejs/realworld - GitHub
Pulled from the latest master, did a clean npm install, while running the app I get many errors like: 'api.js' is imported by ......
Read more >Cannot find module 'X' error in Node.js | bobbyhadz
To solve the "Cannot find module" error in Node.js, make sure to install the package from the error message if it's a third-party...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@danielroe Thank you very much for your time and help. I will refactor my api.
@Ultraviolence322 Thanks - good to see it. Almost certainly if you refactor your api to be a separate serverless function you’ll have better results. The technique in this post might do the trick. Consider also using
puppeteer-core
rather than full-onpuppeteer
. There are other examples out there of serverless use like https://github.com/simonw/puppeteer-screenshot.