I’m trying to utilize the Airtable API for my website’s backend, but there’s an issue when I attempt to use it in Node.js.
When I write the following code:
var Airtable = require('airtable');
And then execute my script with node [filepath], I receive an error indicating:
Error: Cannot find module 'airtable'
I’ve already run:
npm install airtable
So the package should theoretically be installed. What might I be overlooking here?
I’m aiming to set up a server on localhost on port 3000, but I’m stuck at the require() line. Below is the relevant part of my package.json:
{
"name": "package.json",
"version": "1.0.0",
"main": "index.js",
"dependencies": {
"airtable": "^0.7.2",
"express": "^4.17.1",
"require": "^2.4.20"
}
}
Check if you’re using yarn or pnpm instead of npm. Mixed package managers mess up module resolution since they create different lockfiles. I hit this exact issue - had yarn installed globally but was running npm commands. The modules went to yarn’s cache where Node couldn’t find them. Try npm ci instead of npm install for a clean install from your package-lock.json. Also check if your Node version works with airtable - look at their docs. Newer Node versions often break older packages, and 0.7.2 is pretty old. You might need to update airtable or downgrade Node temporarily.
You’re probably running your script from the wrong directory. Node looks for modules in the current directory’s node_modules folder.
Run your script from the same directory where you ran npm install. If your package.json is in /project/ but you’re running from /project/src/, Node won’t find the modules.
This trips up developers all the time. Quick check - run ls node_modules where you’re executing your script. No airtable folder? That’s your problem.
Or try npm list airtable to see if it’s actually installed where you think.
If you need to run scripts from different directories, use npm scripts in your package.json instead of calling node directly.
It seems that you might be facing a conflict with your Node.js versions, possibly due to nvm or similar tools. A common occurrence is having some packages installed in one version while executing scripts in another, leading to module resolution issues. Check your active Node.js and npm paths using which node and which npm to ensure they align. Running node -e "console.log(module.paths)" can give you insights into where Node is searching for modules. If permission problems occurred during installation, you could try deleting your node_modules folder using rm -rf node_modules and perform a fresh installation with npm install. Additionally, on Windows systems, ensure you are using a consistent terminal, as Command Prompt and PowerShell may have different path settings.
Had this exact same issue last month. Your package.json probably has a weird config - that “require” dependency looks suspicious and could be messing with module resolution. Remove that “require”: “^2.4.20” line from your dependencies since it’s not a real package and might interfere with Node’s built-in require function. After you edit package.json, nuke your node_modules folder and run npm install again. Also check if you accidentally installed airtable globally instead of locally. Run npm list --depth=0 in your project directory to see what’s actually installed locally, or npm list -g --depth=0 for global packages. npm sometimes fails silently when there are dependency conflicts, so always check the install output for warnings or errors.
This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.